Search in sources :

Example 26 with DerValue

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

the class LdapV3DNStrConverter method encodeAVA.

/**
 * Converts a AVA to a Ldap v3 DN String (except in unicode).
 *
 * @param ava an AVA
 *
 * @return a Ldap v3 DN string (except in unicode).
 *
 * @exception IOException If an error is encountered during exception.
 */
@Override
public String encodeAVA(AVA ava) throws IOException {
    if (ava == null) {
        return "";
    }
    ObjectIdentifier oid = ava.getOid();
    DerValue value = ava.getValue();
    String keyword, valueStr;
    // get attribute name
    keyword = encodeOID(oid);
    valueStr = encodeValue(value, oid);
    return keyword + "=" + valueStr;
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) ObjectIdentifier(org.mozilla.jss.netscape.security.util.ObjectIdentifier)

Example 27 with DerValue

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

the class CertificateSubjectName method decodeEx.

/**
 * Decode the name in DER form from the stream.
 *
 * @param in the InputStream to marshal the contents from.
 * @exception IOException on errors.
 */
public void decodeEx(InputStream in) throws IOException {
    DerValue derVal = new DerValue(in);
    // dnName = new X500Name(derVal);
    dnName = new X500Name(derVal.toByteArray());
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 28 with DerValue

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

the class DirStrConverter method getValue.

/**
 * Like getValue(String) with specified DER tags as encoding order.
 */
@Override
public DerValue getValue(String valueString, byte[] tags) throws IOException {
    if (tags == null || tags.length == 0)
        tags = DefEncodingOrder;
    for (int i = 0; i < tags.length; i++) {
        try {
            CharsetEncoder encoder = ASN1CharStrConvMap.getDefault().getEncoder(tags[i]);
            if (encoder == null)
                continue;
            CharBuffer charBuffer = CharBuffer.wrap(valueString.toCharArray());
            ByteBuffer byteBuffer = encoder.encode(charBuffer);
            return new DerValue(tags[i], byteBuffer.array(), byteBuffer.arrayOffset(), byteBuffer.limit());
        } catch (CharacterCodingException e) {
            continue;
        }
    }
    throw new IOException("Cannot convert the directory string value to a ASN.1 type");
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) CharBuffer(java.nio.CharBuffer) CharacterCodingException(java.nio.charset.CharacterCodingException) IOException(java.io.IOException) CharsetEncoder(java.nio.charset.CharsetEncoder) ByteBuffer(java.nio.ByteBuffer)

Example 29 with DerValue

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

the class PrintableConverter method getValue.

@Override
public DerValue getValue(String valueString, byte[] tags) throws IOException {
    try {
        CharsetEncoder encoder = ASN1CharStrConvMap.getDefault().getEncoder(DerValue.tag_PrintableString);
        if (encoder == null)
            throw new IOException("No encoder for printable");
        CharBuffer charBuffer = CharBuffer.wrap(valueString.toCharArray());
        ByteBuffer byteBuffer = encoder.encode(charBuffer);
        return new DerValue(DerValue.tag_PrintableString, byteBuffer.array(), byteBuffer.arrayOffset(), byteBuffer.limit());
    } catch (CharacterCodingException e) {
        throw new IllegalArgumentException("Invalid Printable String AVA Value", e);
    }
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) CharBuffer(java.nio.CharBuffer) IOException(java.io.IOException) CharacterCodingException(java.nio.charset.CharacterCodingException) CharsetEncoder(java.nio.charset.CharsetEncoder) ByteBuffer(java.nio.ByteBuffer)

Example 30 with DerValue

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

the class OtherName method decodeThis.

// Decode this extension value
private void decodeThis(DerValue derVal) throws IOException {
    // if (derVal.tag != DerValue.tag_Sequence) {
    // throw new IOException("Invalid encoding for other name");
    // }
    // Decode all the Attributes
    mOID = derVal.data.getOID();
    // skip tag
    DerValue tag = derVal.data.getDerValue();
    // read data
    DerValue data = tag.data.getDerValue();
    mData = data.toByteArray();
}
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