本文整理匯總了Java中java.security.cert.PKIXParameters.getTrustAnchors方法的典型用法代碼示例。如果您正苦於以下問題:Java PKIXParameters.getTrustAnchors方法的具體用法?Java PKIXParameters.getTrustAnchors怎麽用?Java PKIXParameters.getTrustAnchors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.cert.PKIXParameters
的用法示例。
在下文中一共展示了PKIXParameters.getTrustAnchors方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getInstance
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
/**
* Returns an instance with the parameters of a given
* <code>PKIXParameters</code> object.
*
* @param pkixParams The given <code>PKIXParameters</code>
* @return an extended PKIX params object
*/
public static ExtendedPKIXParameters getInstance(PKIXParameters pkixParams)
{
ExtendedPKIXParameters params;
try
{
params = new ExtendedPKIXParameters(pkixParams.getTrustAnchors());
}
catch (Exception e)
{
// cannot happen
throw new RuntimeException(e.getMessage());
}
params.setParams(pkixParams);
return params;
}
示例2: getInstance
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
/**
* Returns an instance of <code>ExtendedPKIXParameters</code> which can be
* safely casted to <code>ExtendedPKIXBuilderParameters</code>.
* <p>
* This method can be used to get a copy from other
* <code>PKIXBuilderParameters</code>, <code>PKIXParameters</code>,
* and <code>ExtendedPKIXParameters</code> instances.
*
* @param pkixParams The PKIX parameters to create a copy of.
* @return An <code>ExtendedPKIXBuilderParameters</code> instance.
*/
public static ExtendedPKIXParameters getInstance(PKIXParameters pkixParams)
{
ExtendedPKIXBuilderParameters params;
try
{
params = new ExtendedPKIXBuilderParameters(pkixParams
.getTrustAnchors(), X509CertStoreSelector
.getInstance((X509CertSelector) pkixParams
.getTargetCertConstraints()));
}
catch (Exception e)
{
// cannot happen
throw new RuntimeException(e.getMessage());
}
params.setParams(pkixParams);
return params;
}
示例3: testPKIXParametersSet02
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
/**
* Test #2 for <code>PKIXParameters(Set)</code> constructor<br>
* Assertion: ... the <code>Set</code> is copied to protect against
* subsequent modifications
* @throws InvalidAlgorithmParameterException
*/
public final void testPKIXParametersSet02()
throws InvalidAlgorithmParameterException {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
HashSet originalSet = (HashSet)taSet;
HashSet originalSetCopy = (HashSet)originalSet.clone();
// create test object using originalSet
PKIXParameters pp = new PKIXParameters(originalSetCopy);
// modify originalSet
originalSetCopy.clear();
// check that test object's internal state
// has not been affected by the above modification
Set returnedSet = pp.getTrustAnchors();
assertEquals(originalSet, returnedSet);
}
示例4: testGetTrustAnchors02
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
/**
* Test #2 for <code>getTrustAnchors()</code> method<br>
* Assertion: an immutable <code>Set</code> of <code>TrustAnchors</code>
* (never <code>null</code>)
* @throws InvalidAlgorithmParameterException
*/
public final void testGetTrustAnchors02() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
PKIXParameters p = new PKIXParameters(taSet);
Set s = p.getTrustAnchors();
try {
// try to modify returned set
s.add(new Object());
fail("must be immutable");
} catch (Exception e) {
}
}
示例5: testSetTrustAnchors04
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
/**
* Test #4 for <code>setTrustAnchors(Set)</code> method<br>
* Assertion: <code>ClassCastException</code> -
* if any of the elements in the set are not of type
* <code>java.security.cert.TrustAnchor</code>
* @throws InvalidAlgorithmParameterException
*/
public final void testSetTrustAnchors04() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
PKIXParameters p = new PKIXParameters(taSet);
Set s = new HashSet(p.getTrustAnchors());
s.add(new Object());
try {
p.setTrustAnchors(s);
fail("ClassCastException expected");
} catch (ClassCastException e) {
}
}
示例6: testSetTrustAnchors05
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
/**
* Test #5 for <code>setTrustAnchors(Set)</code> method<br>
* Assertion: <code>Set</code> is copied to protect against
* subsequent modifications
* @throws InvalidAlgorithmParameterException
* @throws KeyStoreException
*/
public final void testSetTrustAnchors05() throws Exception {
// use several trusted certs in this test
KeyStore ks = TestUtils.getKeyStore(true, TestUtils.TRUSTED);
if (ks == null) {
fail(getName() + ": not performed (could not create test KeyStore)");
}
PKIXParameters p = new PKIXParameters(ks);
// prepare new Set
HashSet newSet = new HashSet(p.getTrustAnchors());
HashSet newSetCopy = (HashSet)newSet.clone();
// set new Set
p.setTrustAnchors(newSetCopy);
// modify set - remove one element
assertTrue("modified", newSetCopy.remove(newSetCopy.iterator().next()));
// check that set maintained internally has
// not been changed by the above modification
assertEquals("isCopied", newSet, p.getTrustAnchors());
}
示例7: Builder
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
public Builder(PKIXParameters baseParameters)
{
this.baseParameters = (PKIXParameters)baseParameters.clone();
CertSelector constraints = baseParameters.getTargetCertConstraints();
if (constraints != null)
{
this.targetConstraints = new PKIXCertStoreSelector.Builder(constraints).build();
}
Date checkDate = baseParameters.getDate();
this.date = (checkDate == null) ? new Date() : checkDate;
this.revocationEnabled = baseParameters.isRevocationEnabled();
this.trustAnchors = baseParameters.getTrustAnchors();
}