java.security.cert.PolicyQualifierInfo Java Examples

The following examples show how to use java.security.cert.PolicyQualifierInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PolicyInformation.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #2
Source File: PolicyInformation.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #3
Source File: PolicyInformation.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #4
Source File: PolicyInformation.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #5
Source File: PolicyQualifierInfoTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Test #2 for <code>getPolicyQualifier()</code> method
 * Assertion: a copy is returned each time
 *
 * @throws IOException
 */
public final void testGetPolicyQualifier02() throws IOException {
    // get valid encoding
    byte[] encoding = getDerEncoding();
    // get policy qualifier encoding
    byte[] pqEncoding = new byte[28];
    System.arraycopy(encoding, 12, pqEncoding, 0, pqEncoding.length);
    // pass valid array
    PolicyQualifierInfo i = new PolicyQualifierInfo(encoding);
    // get encoding
    byte[] pqEncodingRet = i.getPolicyQualifier();
    // modify returned array
    pqEncodingRet[0] = (byte)0;
    // get encoding again
    byte[] pqEncodingRet1 = i.getPolicyQualifier();
    //
    assertNotSame(pqEncodingRet, pqEncodingRet1);
    // check that above modification did not change
    // internal state of the PolicyQualifierInfo instance
    assertTrue(Arrays.equals(pqEncoding, pqEncodingRet1));
}
 
Example #6
Source File: PolicyInformation.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Set the attribute value.
 */
@SuppressWarnings("unchecked") // Checked with instanceof
public void set(String name, Object obj) throws IOException {
    if (name.equalsIgnoreCase(ID)) {
        if (obj instanceof CertificatePolicyId)
            policyIdentifier = (CertificatePolicyId)obj;
        else
            throw new IOException("Attribute value must be instance " +
                "of CertificatePolicyId.");
    } else if (name.equalsIgnoreCase(QUALIFIERS)) {
        if (policyIdentifier == null) {
            throw new IOException("Attribute must have a " +
                "CertificatePolicyIdentifier value before " +
                "PolicyQualifierInfo can be set.");
        }
        if (obj instanceof Set) {
            Iterator<?> i = ((Set<?>)obj).iterator();
            while (i.hasNext()) {
                Object obj1 = i.next();
                if (!(obj1 instanceof PolicyQualifierInfo)) {
                    throw new IOException("Attribute value must be a" +
                                "Set of PolicyQualifierInfo objects.");
                }
            }
            policyQualifiers = (Set<PolicyQualifierInfo>) obj;
        } else {
            throw new IOException("Attribute value must be of type Set.");
        }
    } else {
        throw new IOException("Attribute name [" + name +
            "] not recognized by PolicyInformation");
    }
}
 
Example #7
Source File: PolicyInformation.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #8
Source File: PolicyInformation.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #9
Source File: PolicyInformation.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #10
Source File: PolicyInformation.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #11
Source File: PolicyInformation.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #12
Source File: PolicyInformation.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #13
Source File: PolicyQualifierInfoTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Test #4 for <code>PolicyQualifierInfo</code> constructor<br>
 * Assertion: The encoded byte array is copied on construction
 *
 * @throws IOException
 */
public final void testPolicyQualifierInfo04() throws IOException  {
    // get valid encoding
    byte[] encoding = getDerEncoding();
    byte[] encodingCopy = encoding.clone();
    // pass valid array
    PolicyQualifierInfo i = new PolicyQualifierInfo(encodingCopy);
    // get encoding
    byte[] encodingRet = i.getEncoded();
    // check returned array
    assertTrue(Arrays.equals(encoding, encodingRet));
    // modify input
    encodingCopy[0] = (byte)0;
    // get encoding again
    byte[] encodingRet1 = i.getEncoded();
    // check that above modification did not change
    // internal state of the PolicyQualifierInfo instance
    assertTrue(Arrays.equals(encoding, encodingRet1));
}
 
Example #14
Source File: PolicyInformation.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #15
Source File: PolicyInformation.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #16
Source File: PolicyInformation.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an instance of PolicyInformation, decoding from
 * the passed DerValue.
 *
 * @param val the DerValue to construct the PolicyInformation from.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of PolicyInformation");
    }
    policyIdentifier = new CertificatePolicyId(val.data.getDerValue());
    if (val.data.available() != 0) {
        policyQualifiers = new LinkedHashSet<PolicyQualifierInfo>();
        DerValue opt = val.data.getDerValue();
        if (opt.tag != DerValue.tag_Sequence)
            throw new IOException("Invalid encoding of PolicyInformation");
        if (opt.data.available() == 0)
            throw new IOException("No data available in policyQualifiers");
        while (opt.data.available() != 0)
            policyQualifiers.add(new PolicyQualifierInfo
                    (opt.data.getDerValue().toByteArray()));
    } else {
        policyQualifiers = Collections.emptySet();
    }
}
 
Example #17
Source File: PolicyInformation.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the attribute value.
 */
@SuppressWarnings("unchecked") // Checked with instanceof
public void set(String name, Object obj) throws IOException {
    if (name.equalsIgnoreCase(ID)) {
        if (obj instanceof CertificatePolicyId)
            policyIdentifier = (CertificatePolicyId)obj;
        else
            throw new IOException("Attribute value must be instance " +
                "of CertificatePolicyId.");
    } else if (name.equalsIgnoreCase(QUALIFIERS)) {
        if (policyIdentifier == null) {
            throw new IOException("Attribute must have a " +
                "CertificatePolicyIdentifier value before " +
                "PolicyQualifierInfo can be set.");
        }
        if (obj instanceof Set) {
            Iterator<?> i = ((Set<?>)obj).iterator();
            while (i.hasNext()) {
                Object obj1 = i.next();
                if (!(obj1 instanceof PolicyQualifierInfo)) {
                    throw new IOException("Attribute value must be a" +
                                "Set of PolicyQualifierInfo objects.");
                }
            }
            policyQualifiers = (Set<PolicyQualifierInfo>) obj;
        } else {
            throw new IOException("Attribute value must be of type Set.");
        }
    } else {
        throw new IOException("Attribute name [" + name +
            "] not recognized by PolicyInformation");
    }
}
 
Example #18
Source File: PolicyInformation.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Write the PolicyInformation to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception IOException on encoding errors.
 */
public void encode(DerOutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    policyIdentifier.encode(tmp);
    if (!policyQualifiers.isEmpty()) {
        DerOutputStream tmp2 = new DerOutputStream();
        for (PolicyQualifierInfo pq : policyQualifiers) {
            tmp2.write(pq.getEncoded());
        }
        tmp.write(DerValue.tag_Sequence, tmp2);
    }
    out.write(DerValue.tag_Sequence, tmp);
}
 
Example #19
Source File: PolicyInformation.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an instance of PolicyInformation
 *
 * @param policyIdentifier the policyIdentifier as a
 *          CertificatePolicyId
 * @param policyQualifiers a Set of PolicyQualifierInfo objects.
 *          Must not be NULL. Specify an empty Set for no qualifiers.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(CertificatePolicyId policyIdentifier,
        Set<PolicyQualifierInfo> policyQualifiers) throws IOException {
    if (policyQualifiers == null) {
        throw new NullPointerException("policyQualifiers is null");
    }
    this.policyQualifiers =
        new LinkedHashSet<PolicyQualifierInfo>(policyQualifiers);
    this.policyIdentifier = policyIdentifier;
}
 
Example #20
Source File: PolicyInformation.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write the PolicyInformation to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception IOException on encoding errors.
 */
public void encode(DerOutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    policyIdentifier.encode(tmp);
    if (!policyQualifiers.isEmpty()) {
        DerOutputStream tmp2 = new DerOutputStream();
        for (PolicyQualifierInfo pq : policyQualifiers) {
            tmp2.write(pq.getEncoded());
        }
        tmp.write(DerValue.tag_Sequence, tmp2);
    }
    out.write(DerValue.tag_Sequence, tmp);
}
 
Example #21
Source File: PolicyInformation.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the attribute value.
 */
@SuppressWarnings("unchecked") // Checked with instanceof
public void set(String name, Object obj) throws IOException {
    if (name.equalsIgnoreCase(ID)) {
        if (obj instanceof CertificatePolicyId)
            policyIdentifier = (CertificatePolicyId)obj;
        else
            throw new IOException("Attribute value must be instance " +
                "of CertificatePolicyId.");
    } else if (name.equalsIgnoreCase(QUALIFIERS)) {
        if (policyIdentifier == null) {
            throw new IOException("Attribute must have a " +
                "CertificatePolicyIdentifier value before " +
                "PolicyQualifierInfo can be set.");
        }
        if (obj instanceof Set) {
            Iterator<?> i = ((Set<?>)obj).iterator();
            while (i.hasNext()) {
                Object obj1 = i.next();
                if (!(obj1 instanceof PolicyQualifierInfo)) {
                    throw new IOException("Attribute value must be a" +
                                "Set of PolicyQualifierInfo objects.");
                }
            }
            policyQualifiers = (Set<PolicyQualifierInfo>) obj;
        } else {
            throw new IOException("Attribute value must be of type Set.");
        }
    } else {
        throw new IOException("Attribute name [" + name +
            "] not recognized by PolicyInformation");
    }
}
 
Example #22
Source File: PolicyInformation.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write the PolicyInformation to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception IOException on encoding errors.
 */
public void encode(DerOutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    policyIdentifier.encode(tmp);
    if (!policyQualifiers.isEmpty()) {
        DerOutputStream tmp2 = new DerOutputStream();
        for (PolicyQualifierInfo pq : policyQualifiers) {
            tmp2.write(pq.getEncoded());
        }
        tmp.write(DerValue.tag_Sequence, tmp2);
    }
    out.write(DerValue.tag_Sequence, tmp);
}
 
Example #23
Source File: PolicyInformation.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an instance of PolicyInformation
 *
 * @param policyIdentifier the policyIdentifier as a
 *          CertificatePolicyId
 * @param policyQualifiers a Set of PolicyQualifierInfo objects.
 *          Must not be NULL. Specify an empty Set for no qualifiers.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(CertificatePolicyId policyIdentifier,
        Set<PolicyQualifierInfo> policyQualifiers) throws IOException {
    if (policyQualifiers == null) {
        throw new NullPointerException("policyQualifiers is null");
    }
    this.policyQualifiers =
        new LinkedHashSet<PolicyQualifierInfo>(policyQualifiers);
    this.policyIdentifier = policyIdentifier;
}
 
Example #24
Source File: PolicyInformation.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write the PolicyInformation to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception IOException on encoding errors.
 */
public void encode(DerOutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    policyIdentifier.encode(tmp);
    if (!policyQualifiers.isEmpty()) {
        DerOutputStream tmp2 = new DerOutputStream();
        for (PolicyQualifierInfo pq : policyQualifiers) {
            tmp2.write(pq.getEncoded());
        }
        tmp.write(DerValue.tag_Sequence, tmp2);
    }
    out.write(DerValue.tag_Sequence, tmp);
}
 
Example #25
Source File: PolicyQualifierInfoTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Test #1 for <code>getPolicyQualifier()</code> method
 * Assertion: Returns the ASN.1 DER encoded form of
 * this <code>PolicyQualifierInfo</code>
 *
 * @throws IOException
 */
public final void testGetPolicyQualifier01() throws IOException {
    // get valid encoding
    byte[] encoding = getDerEncoding();
    // get policy qualifier encoding
    byte[] pqEncoding = new byte[28];
    System.arraycopy(encoding, 12, pqEncoding, 0, pqEncoding.length);
    // pass valid array
    PolicyQualifierInfo i = new PolicyQualifierInfo(encoding);
    // get encoding
    byte[] pqEncodingRet = i.getPolicyQualifier();
    // check returned array
    assertTrue(Arrays.equals(pqEncoding, pqEncodingRet));
}
 
Example #26
Source File: CertPathValidatorUtilities.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
protected static final Set getQualifierSet(ASN1Sequence qualifiers)
    throws CertPathValidatorException
{
    Set pq = new HashSet();

    if (qualifiers == null)
    {
        return pq;
    }

    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    ASN1OutputStream aOut = new ASN1OutputStream(bOut);

    Enumeration e = qualifiers.getObjects();

    while (e.hasMoreElements())
    {
        try
        {
            aOut.writeObject((ASN1Encodable)e.nextElement());

            pq.add(new PolicyQualifierInfo(bOut.toByteArray()));
        }
        catch (IOException ex)
        {
            throw new ExtCertPathValidatorException("Policy qualifier info cannot be decoded.", ex);
        }

        bOut.reset();
    }

    return pq;
}
 
Example #27
Source File: PolicyInformation.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an instance of PolicyInformation
 *
 * @param policyIdentifier the policyIdentifier as a
 *          CertificatePolicyId
 * @param policyQualifiers a Set of PolicyQualifierInfo objects.
 *          Must not be NULL. Specify an empty Set for no qualifiers.
 * @exception IOException on decoding errors.
 */
public PolicyInformation(CertificatePolicyId policyIdentifier,
        Set<PolicyQualifierInfo> policyQualifiers) throws IOException {
    if (policyQualifiers == null) {
        throw new NullPointerException("policyQualifiers is null");
    }
    this.policyQualifiers =
        new LinkedHashSet<PolicyQualifierInfo>(policyQualifiers);
    this.policyIdentifier = policyIdentifier;
}
 
Example #28
Source File: PolicyInformation.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write the PolicyInformation to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception IOException on encoding errors.
 */
public void encode(DerOutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    policyIdentifier.encode(tmp);
    if (!policyQualifiers.isEmpty()) {
        DerOutputStream tmp2 = new DerOutputStream();
        for (PolicyQualifierInfo pq : policyQualifiers) {
            tmp2.write(pq.getEncoded());
        }
        tmp.write(DerValue.tag_Sequence, tmp2);
    }
    out.write(DerValue.tag_Sequence, tmp);
}
 
Example #29
Source File: PolicyInformation.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the attribute value.
 */
@SuppressWarnings("unchecked") // Checked with instanceof
public void set(String name, Object obj) throws IOException {
    if (name.equalsIgnoreCase(ID)) {
        if (obj instanceof CertificatePolicyId)
            policyIdentifier = (CertificatePolicyId)obj;
        else
            throw new IOException("Attribute value must be instance " +
                "of CertificatePolicyId.");
    } else if (name.equalsIgnoreCase(QUALIFIERS)) {
        if (policyIdentifier == null) {
            throw new IOException("Attribute must have a " +
                "CertificatePolicyIdentifier value before " +
                "PolicyQualifierInfo can be set.");
        }
        if (obj instanceof Set) {
            Iterator<?> i = ((Set<?>)obj).iterator();
            while (i.hasNext()) {
                Object obj1 = i.next();
                if (!(obj1 instanceof PolicyQualifierInfo)) {
                    throw new IOException("Attribute value must be a" +
                                "Set of PolicyQualifierInfo objects.");
                }
            }
            policyQualifiers = (Set<PolicyQualifierInfo>) obj;
        } else {
            throw new IOException("Attribute value must be of type Set.");
        }
    } else {
        throw new IOException("Attribute name [" + name +
            "] not recognized by PolicyInformation");
    }
}
 
Example #30
Source File: PolicyInformation.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the attribute value.
 */
@SuppressWarnings("unchecked") // Checked with instanceof
public void set(String name, Object obj) throws IOException {
    if (name.equalsIgnoreCase(ID)) {
        if (obj instanceof CertificatePolicyId)
            policyIdentifier = (CertificatePolicyId)obj;
        else
            throw new IOException("Attribute value must be instance " +
                "of CertificatePolicyId.");
    } else if (name.equalsIgnoreCase(QUALIFIERS)) {
        if (policyIdentifier == null) {
            throw new IOException("Attribute must have a " +
                "CertificatePolicyIdentifier value before " +
                "PolicyQualifierInfo can be set.");
        }
        if (obj instanceof Set) {
            Iterator<?> i = ((Set<?>)obj).iterator();
            while (i.hasNext()) {
                Object obj1 = i.next();
                if (!(obj1 instanceof PolicyQualifierInfo)) {
                    throw new IOException("Attribute value must be a" +
                                "Set of PolicyQualifierInfo objects.");
                }
            }
            policyQualifiers = (Set<PolicyQualifierInfo>) obj;
        } else {
            throw new IOException("Attribute value must be of type Set.");
        }
    } else {
        throw new IOException("Attribute name [" + name +
            "] not recognized by PolicyInformation");
    }
}