Search in sources :

Example 16 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class Attribute method encodeValueSet.

// encode the attribute object
private void encodeValueSet(OutputStream out) throws IOException {
    try (DerOutputStream tmp2 = new DerOutputStream()) {
        DerOutputStream tmp = new DerOutputStream();
        // get the attribute converter
        AVAValueConverter converter = attrMap.getValueConverter(oid);
        if (converter == null) {
            converter = new GenericValueConverter();
        // throw new IOException("Converter not found: unsupported attribute type");
        }
        // loop through all the values and encode
        Enumeration<String> vals = valueSet.elements();
        while (vals.hasMoreElements()) {
            String val = vals.nextElement();
            DerValue derobj = converter.getValue(val);
            derobj.encode(tmp);
        }
        tmp2.write(DerValue.tag_SetOf, tmp);
        out.write(tmp2.toByteArray());
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 17 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class Attribute method decodeValueSet.

// decode the attribute value set
private void decodeValueSet(DerValue val) throws IOException {
    // pre-condition verification
    if (val == null) {
        throw new IOException("Invalid Input - null passed.");
    }
    AVAValueConverter converter = attrMap.getValueConverter(this.oid);
    if (converter == null) {
        converter = new GenericValueConverter();
    // throw new IOException("Attribute is not supported - not in attr map");
    }
    if (val.tag != DerValue.tag_SetOf) {
        throw new IOException("Invalid encoding for Attribute Value Set.");
    }
    if (val.data.available() == 0) {
        throw new IOException("No data available in " + "passed DER encoded attribute value set.");
    }
    // get the value set
    while (val.data.available() != 0) {
        DerValue value = val.data.getDerValue();
        valueSet.addElement(converter.getAsString(value));
    }
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) IOException(java.io.IOException)

Example 18 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class DSAParameters method engineInit.

@Override
protected void engineInit(byte[] params) throws IOException {
    DerValue encodedParams = new DerValue(params);
    if (encodedParams.tag != DerValue.tag_Sequence) {
        throw new IOException("DSA params parsing error");
    }
    encodedParams.data.reset();
    this.p = encodedParams.data.getInteger().toBigInteger();
    this.q = encodedParams.data.getInteger().toBigInteger();
    this.g = encodedParams.data.getInteger().toBigInteger();
    if (encodedParams.data.available() != 0) {
        throw new IOException("encoded params have " + encodedParams.data.available() + " extra bytes");
    }
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) IOException(java.io.IOException)

Example 19 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class ExtendedKeyUsageExtension method decodeThis.

private void decodeThis() throws IOException {
    DerValue val = new DerValue(this.extensionValue);
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of AuthInfoAccess extension");
    }
    if (oidSet == null)
        oidSet = new Vector<>();
    while (val.data.available() != 0) {
        DerValue oidVal = val.data.getDerValue();
        oidSet.addElement(oidVal.getOID());
    }
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) IOException(java.io.IOException) Vector(java.util.Vector)

Example 20 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class CertificateAlgorithmId method decode.

/**
 * Decode the algorithm identifier from the passed stream.
 *
 * @param in the InputStream to unmarshal the contents from.
 * @exception IOException on errors.
 */
@Override
public void decode(InputStream in) throws IOException {
    DerValue derVal = new DerValue(in);
    algId = AlgorithmId.parse(derVal);
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Aggregations

DerValue (org.mozilla.jss.netscape.security.util.DerValue)70 IOException (java.io.IOException)31 DerInputStream (org.mozilla.jss.netscape.security.util.DerInputStream)20 DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)8 ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ByteBuffer (java.nio.ByteBuffer)4 CharBuffer (java.nio.CharBuffer)4 CharacterCodingException (java.nio.charset.CharacterCodingException)4 CharsetEncoder (java.nio.charset.CharsetEncoder)4 MessageDigest (java.security.MessageDigest)4 CRLException (java.security.cert.CRLException)4 BitArray (org.mozilla.jss.netscape.security.util.BitArray)4 AuthorityKeyIdentifierExtension (org.mozilla.jss.netscape.security.x509.AuthorityKeyIdentifierExtension)4 KeyIdentifier (org.mozilla.jss.netscape.security.x509.KeyIdentifier)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InvalidKeyException (java.security.InvalidKeyException)3 BigInt (org.mozilla.jss.netscape.security.util.BigInt)3 GeneralName (org.mozilla.jss.netscape.security.x509.GeneralName)3 CertificateException (java.security.cert.CertificateException)2