Search in sources :

Example 51 with ASN1Exception

use of com.github.zhenwei.core.asn1.ASN1Exception in project ldapsdk by pingidentity.

the class Modification method decode.

/**
 * Decodes the provided ASN.1 sequence as an LDAP modification.
 *
 * @param  modificationSequence  The ASN.1 sequence to decode as an LDAP
 *                               modification.  It must not be {@code null}.
 *
 * @return  The decoded LDAP modification.
 *
 * @throws  LDAPException  If a problem occurs while trying to decode the
 *                         provided ASN.1 sequence as an LDAP modification.
 */
@NotNull()
public static Modification decode(@NotNull final ASN1Sequence modificationSequence) throws LDAPException {
    Validator.ensureNotNull(modificationSequence);
    final ASN1Element[] modificationElements = modificationSequence.elements();
    if (modificationElements.length != 2) {
        throw new LDAPException(ResultCode.DECODING_ERROR, ERR_MOD_DECODE_INVALID_ELEMENT_COUNT.get(modificationElements.length));
    }
    final int modType;
    try {
        final ASN1Enumerated typeEnumerated = ASN1Enumerated.decodeAsEnumerated(modificationElements[0]);
        modType = typeEnumerated.intValue();
    } catch (final ASN1Exception ae) {
        Debug.debugException(ae);
        throw new LDAPException(ResultCode.DECODING_ERROR, ERR_MOD_DECODE_CANNOT_PARSE_MOD_TYPE.get(StaticUtils.getExceptionMessage(ae)), ae);
    }
    final ASN1Sequence attrSequence;
    try {
        attrSequence = ASN1Sequence.decodeAsSequence(modificationElements[1]);
    } catch (final ASN1Exception ae) {
        Debug.debugException(ae);
        throw new LDAPException(ResultCode.DECODING_ERROR, ERR_MOD_DECODE_CANNOT_PARSE_ATTR.get(StaticUtils.getExceptionMessage(ae)), ae);
    }
    final ASN1Element[] attrElements = attrSequence.elements();
    if (attrElements.length != 2) {
        throw new LDAPException(ResultCode.DECODING_ERROR, ERR_MOD_DECODE_INVALID_ATTR_ELEMENT_COUNT.get(attrElements.length));
    }
    final String attrName = ASN1OctetString.decodeAsOctetString(attrElements[0]).stringValue();
    final ASN1Set valueSet;
    try {
        valueSet = ASN1Set.decodeAsSet(attrElements[1]);
    } catch (final ASN1Exception ae) {
        Debug.debugException(ae);
        throw new LDAPException(ResultCode.DECODING_ERROR, ERR_MOD_DECODE_CANNOT_PARSE_ATTR_VALUE_SET.get(StaticUtils.getExceptionMessage(ae)), ae);
    }
    final ASN1Element[] valueElements = valueSet.elements();
    final ASN1OctetString[] values = new ASN1OctetString[valueElements.length];
    for (int i = 0; i < values.length; i++) {
        values[i] = ASN1OctetString.decodeAsOctetString(valueElements[i]);
    }
    return new Modification(ModificationType.valueOf(modType), attrName, values);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Exception(com.unboundid.asn1.ASN1Exception) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) NotNull(com.unboundid.util.NotNull)

Example 52 with ASN1Exception

use of com.github.zhenwei.core.asn1.ASN1Exception in project ldapsdk by pingidentity.

the class JNDIConverter method convertControl.

/**
 * Converts the provided JNDI control to an LDAP SDK control.
 *
 * @param  c  The control to be converted.
 *
 * @return  The LDAP SDK control that corresponds to the provided JNDI
 *          control.
 *
 * @throws  NamingException  If a problem is encountered during the conversion
 *                           process.
 */
@Nullable
public static Control convertControl(@Nullable final javax.naming.ldap.Control c) throws NamingException {
    if (c == null) {
        return null;
    }
    final ASN1OctetString value;
    final byte[] valueBytes = c.getEncodedValue();
    if ((valueBytes == null) || (valueBytes.length == 0)) {
        value = null;
    } else {
        try {
            value = ASN1OctetString.decodeAsOctetString(valueBytes);
        } catch (final ASN1Exception ae) {
            throw new NamingException(StaticUtils.getExceptionMessage(ae));
        }
    }
    return new Control(c.getID(), c.isCritical(), value);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) BasicControl(javax.naming.ldap.BasicControl) ASN1Exception(com.unboundid.asn1.ASN1Exception) NamingException(javax.naming.NamingException) Nullable(com.unboundid.util.Nullable)

Example 53 with ASN1Exception

use of com.github.zhenwei.core.asn1.ASN1Exception in project ldapsdk by pingidentity.

the class EndTransactionExtendedResult method decodeOpControls.

/**
 * Decodes the provided ASN.1 element as an update controls sequence.  Each
 * element of the sequence should itself be a sequence containing the message
 * ID associated with the operation in which the control was returned and a
 * sequence of the controls included in the response for that operation.
 *
 * @param  element     The ASN.1 element to be decoded.
 * @param  controlMap  The map into which to place the decoded controls.
 *
 * @throws  LDAPException  If a problem occurs while attempting to decode the
 *                         contents of the provided ASN.1 element.
 */
private static void decodeOpControls(@NotNull final ASN1Element element, @NotNull final Map<Integer, Control[]> controlMap) throws LDAPException {
    final ASN1Sequence ctlsSequence;
    try {
        ctlsSequence = ASN1Sequence.decodeAsSequence(element);
    } catch (final ASN1Exception ae) {
        Debug.debugException(ae);
        throw new LDAPException(ResultCode.DECODING_ERROR, ERR_END_TXN_RESPONSE_CONTROLS_NOT_SEQUENCE.get(ae), ae);
    }
    for (final ASN1Element e : ctlsSequence.elements()) {
        final ASN1Sequence ctlSequence;
        try {
            ctlSequence = ASN1Sequence.decodeAsSequence(e);
        } catch (final ASN1Exception ae) {
            Debug.debugException(ae);
            throw new LDAPException(ResultCode.DECODING_ERROR, ERR_END_TXN_RESPONSE_CONTROL_NOT_SEQUENCE.get(ae), ae);
        }
        final ASN1Element[] ctlSequenceElements = ctlSequence.elements();
        if (ctlSequenceElements.length != 2) {
            throw new LDAPException(ResultCode.DECODING_ERROR, ERR_END_TXN_RESPONSE_CONTROL_INVALID_ELEMENT_COUNT.get(ctlSequenceElements.length));
        }
        final int msgID;
        try {
            msgID = ASN1Integer.decodeAsInteger(ctlSequenceElements[0]).intValue();
        } catch (final ASN1Exception ae) {
            Debug.debugException(ae);
            throw new LDAPException(ResultCode.DECODING_ERROR, ERR_END_TXN_RESPONSE_CONTROL_MSGID_NOT_INT.get(ae), ae);
        }
        final ASN1Sequence controlsSequence;
        try {
            controlsSequence = ASN1Sequence.decodeAsSequence(ctlSequenceElements[1]);
        } catch (final ASN1Exception ae) {
            Debug.debugException(ae);
            throw new LDAPException(ResultCode.DECODING_ERROR, ERR_END_TXN_RESPONSE_CONTROLS_ELEMENT_NOT_SEQUENCE.get(ae), ae);
        }
        final Control[] controls = Control.decodeControls(controlsSequence);
        if (controls.length == 0) {
            continue;
        }
        controlMap.put(msgID, controls);
    }
}
Also used : Control(com.unboundid.ldap.sdk.Control) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) LDAPException(com.unboundid.ldap.sdk.LDAPException) ASN1Exception(com.unboundid.asn1.ASN1Exception) ASN1Element(com.unboundid.asn1.ASN1Element)

Example 54 with ASN1Exception

use of com.github.zhenwei.core.asn1.ASN1Exception in project ldapsdk by pingidentity.

the class JNDIExtendedRequest method toSDKExtendedRequest.

/**
 * Retrieves an LDAP SDK extended request that is the equivalent of the
 * provided JNDI extended request.
 *
 * @param  r  The JNDI extended request to convert to an LDAP SDK extended
 *            request.
 *
 * @return  The LDAP SDK extended request converted from the provided JNDI
 *          extended request.
 *
 * @throws  NamingException  If a problem occurs while decoding the provided
 *                           JNDI extended request as an SDK extended request.
 */
@Nullable()
public static ExtendedRequest toSDKExtendedRequest(@Nullable final javax.naming.ldap.ExtendedRequest r) throws NamingException {
    if (r == null) {
        return null;
    }
    final ASN1OctetString value;
    final byte[] valueBytes = r.getEncodedValue();
    if (valueBytes == null) {
        value = null;
    } else {
        try {
            value = ASN1OctetString.decodeAsOctetString(valueBytes);
        } catch (final ASN1Exception ae) {
            throw new NamingException(StaticUtils.getExceptionMessage(ae));
        }
    }
    return new ExtendedRequest(r.getID(), value);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Exception(com.unboundid.asn1.ASN1Exception) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) NamingException(javax.naming.NamingException) Nullable(com.unboundid.util.Nullable)

Example 55 with ASN1Exception

use of com.github.zhenwei.core.asn1.ASN1Exception in project ldapsdk by pingidentity.

the class EndBatchedTransactionExtendedResult method decodeOpControls.

/**
 * Decodes the provided ASN.1 element as an update controls sequence.  Each
 * element of the sequence should itself be a sequence containing the message
 * ID associated with the operation in which the control was returned and a
 * sequence of the controls included in the response for that operation.
 *
 * @param  element     The ASN.1 element to be decoded.
 * @param  controlMap  The map into which to place the decoded controls.
 *
 * @throws  LDAPException  If a problem occurs while attempting to decode the
 *                         contents of the provided ASN.1 element.
 */
private static void decodeOpControls(@NotNull final ASN1Element element, @NotNull final Map<Integer, Control[]> controlMap) throws LDAPException {
    final ASN1Sequence ctlsSequence;
    try {
        ctlsSequence = ASN1Sequence.decodeAsSequence(element);
    } catch (final ASN1Exception ae) {
        Debug.debugException(ae);
        throw new LDAPException(ResultCode.DECODING_ERROR, ERR_END_TXN_RESPONSE_CONTROLS_NOT_SEQUENCE.get(ae), ae);
    }
    for (final ASN1Element e : ctlsSequence.elements()) {
        final ASN1Sequence ctlSequence;
        try {
            ctlSequence = ASN1Sequence.decodeAsSequence(e);
        } catch (final ASN1Exception ae) {
            Debug.debugException(ae);
            throw new LDAPException(ResultCode.DECODING_ERROR, ERR_END_TXN_RESPONSE_CONTROL_NOT_SEQUENCE.get(ae), ae);
        }
        final ASN1Element[] ctlSequenceElements = ctlSequence.elements();
        if (ctlSequenceElements.length != 2) {
            throw new LDAPException(ResultCode.DECODING_ERROR, ERR_END_TXN_RESPONSE_CONTROL_INVALID_ELEMENT_COUNT.get(ctlSequenceElements.length));
        }
        final int msgID;
        try {
            msgID = ASN1Integer.decodeAsInteger(ctlSequenceElements[0]).intValue();
        } catch (final ASN1Exception ae) {
            Debug.debugException(ae);
            throw new LDAPException(ResultCode.DECODING_ERROR, ERR_END_TXN_RESPONSE_CONTROL_MSGID_NOT_INT.get(ae), ae);
        }
        final ASN1Sequence controlsSequence;
        try {
            controlsSequence = ASN1Sequence.decodeAsSequence(ctlSequenceElements[1]);
        } catch (final ASN1Exception ae) {
            Debug.debugException(ae);
            throw new LDAPException(ResultCode.DECODING_ERROR, ERR_END_TXN_RESPONSE_CONTROLS_ELEMENT_NOT_SEQUENCE.get(ae), ae);
        }
        final Control[] controls = Control.decodeControls(controlsSequence);
        if (controls.length == 0) {
            continue;
        }
        controlMap.put(msgID, controls);
    }
}
Also used : Control(com.unboundid.ldap.sdk.Control) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) LDAPException(com.unboundid.ldap.sdk.LDAPException) ASN1Exception(com.unboundid.asn1.ASN1Exception) ASN1Element(com.unboundid.asn1.ASN1Element)

Aggregations

IOException (java.io.IOException)18 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)16 ASN1Exception (com.unboundid.asn1.ASN1Exception)12 TlvException (es.gob.jmulticard.asn1.TlvException)12 Asn1Exception (sun.security.krb5.Asn1Exception)11 ASN1Element (com.unboundid.asn1.ASN1Element)7 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)7 NotNull (com.unboundid.util.NotNull)7 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)7 CertificateException (java.security.cert.CertificateException)7 X509Certificate (java.security.cert.X509Certificate)7 Asn1Exception (org.kse.utilities.asn1.Asn1Exception)7 ASN1Exception (org.wildfly.security.asn1.ASN1Exception)6 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)5 Cdf (es.gob.jmulticard.asn1.der.pkcs15.Cdf)5 CryptoCardException (es.gob.jmulticard.card.CryptoCardException)5 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)4 DecoderObject (es.gob.jmulticard.asn1.DecoderObject)4 InvalidCardException (es.gob.jmulticard.card.InvalidCardException)4 DerValue (sun.security.util.DerValue)4