Package org.wildfly.security.asn1
Interface ASN1Decoder
- All Known Implementing Classes:
DERDecoder
public interface ASN1Decoder
An interface for decoding ASN.1 encoded values from an input stream.
- Author:
- Farah Juma
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]Decode the next ASN.1 element as a bit string.Decode the next ASN.1 element as a bit string where the value is a ASN.1 INTEGER.Decode the next ASN.1 element as a bit string.default StringDecode the next ASN.1 element as an BMPString.default byte[]Decode the next ASN.1 element as an BMPString.booleanDecode the next ASN.1 element as a boolean value.Decode the next ASN.1 element as an IA5 string.byte[]Decode the next ASN.1 element as an IA5 string.voiddecodeImplicit(int number) Indicate that the next ASN.1 element has the given implicit, context-specific tag.voiddecodeImplicit(int clazz, int number) Indicate that the next ASN.1 element has the given implicit tag.Decode the next ASN.1 element as an integer.voidDecode the next ASN.1 element as a null element.Decode the next ASN.1 element as an object identifier.byte[]Decode the next ASN.1 element as an octet string.Decode the next ASN.1 element as an octet string.decodeOctetStringAsString(String charSet) Decode the next ASN.1 element as an octet string.Decode the next ASN.1 element as a PrintableString.byte[]Decode the next ASN.1 element as a PrintableString.default StringDecode the next ASN.1 element as an UniversalString.default byte[]Decode the next ASN.1 element as an UniversalString.default StringDecode the next ASN.1 element as an UTF8String.default byte[]Decode the next ASN.1 element as an UTF8String.byte[]drain()Drain all of the remaining bytes from the input stream.byte[]Drain all of the bytes from the next ASN.1 element.byte[]Drain the value bytes from the next ASN.1 element.voidAdvance to the end of an explicitly tagged element.voidAdvance to the end of a sequence.voidendSet()Advance to the end of a set.voidendSetOf()Advance to the end of a "set of" element.booleanDetermine if there is at least one more ASN.1 element that can be read.booleanisNextType(int clazz, int number, boolean isConstructed) Determine if the type of the next ASN.1 element matches the given type without actually decoding the next element.intpeekType()Retrieve the type of the next ASN.1 element without actually decoding the next element.voidSkip over the next ASN.1 element.voidstartExplicit(int number) Start decoding an ASN.1 explicitly tagged element.voidstartExplicit(int clazz, int number) Start decoding an ASN.1 explicitly tagged element.voidStart decoding an ASN.1 sequence.voidstartSet()Start decoding an ASN.1 set.voidStart decoding an ASN.1 "set of" element.
-
Method Details
-
startSequence
Start decoding an ASN.1 sequence. All subsequent decode operations will decode elements from this sequence untilendSequence()is called.- Throws:
ASN1Exception- if the next element is not a sequence
-
endSequence
Advance to the end of a sequence. If there are any elements in the sequence that have not yet been decoded, they will be discarded.- Throws:
ASN1Exception- if an error occurs while advancing to the end of the sequence
-
startSet
Start decoding an ASN.1 set. All subsequent decode operations will decode elements from this set untilendSet()is called.- Throws:
ASN1Exception- if the next element is not a set
-
endSet
Advance to the end of a set. If there are any elements in the set that have not yet been decoded, they will be discarded.- Throws:
ASN1Exception- if an error occurs while advancing to the end of the set
-
startSetOf
Start decoding an ASN.1 "set of" element. All subsequent decode operations will decode elements from this set untilendSetOf()is called.- Throws:
ASN1Exception- if the next element is not a set
-
endSetOf
Advance to the end of a "set of" element. If there are any elements in the set that have not yet been decoded, they will be discarded.- Throws:
ASN1Exception- if an error occurs while advancing to the end of the set
-
startExplicit
Start decoding an ASN.1 explicitly tagged element. All subsequent decode operations will decode elements from this explicitly tagged element untilendExplicit()is called.- Parameters:
number- the tag number for the explicit, context-specific tag- Throws:
ASN1Exception- if the next element's type does not match the given type
-
startExplicit
Start decoding an ASN.1 explicitly tagged element. All subsequent decode operations will decode elements from this explicitly tagged element untilendExplicit()is called.- Parameters:
clazz- the class for the explicit tagnumber- the tag number for the explicit tag- Throws:
ASN1Exception- if the next element's type does not match the given type
-
endExplicit
Advance to the end of an explicitly tagged element. If there are any elements within the explicitly tagged element that have not yet been decoded, they will be discarded.- Throws:
ASN1Exception- if an error occurs while advancing to the end of the explicitly tagged element
-
decodeOctetString
Decode the next ASN.1 element as an octet string.- Returns:
- the decoded octet string, as a byte array
- Throws:
ASN1Exception- if the next element is not an octet string
-
decodeOctetStringAsString
Decode the next ASN.1 element as an octet string.- Returns:
- the decoded octet string, as a UTF-8 string
- Throws:
ASN1Exception- if the next element is not an octet string
-
decodeOctetStringAsString
Decode the next ASN.1 element as an octet string.- Parameters:
charSet- the character set to use when decoding- Returns:
- the decoded octet string
- Throws:
ASN1Exception- if the next element is not an octet string
-
decodeIA5String
Decode the next ASN.1 element as an IA5 string.- Returns:
- the decoded IA5 string
- Throws:
ASN1Exception- if the next element is not an IA5 string
-
decodeIA5StringAsBytes
Decode the next ASN.1 element as an IA5 string.- Returns:
- the decoded IA5 string, as a byte array
- Throws:
ASN1Exception- if the next element is not an IA5 string
-
decodeBitString
Decode the next ASN.1 element as a bit string.- Returns:
- the decoded bit string as a byte array, with any unused bits removed
- Throws:
ASN1Exception- if the next element is not a bit string
-
decodeBitStringAsInteger
BigInteger decodeBitStringAsInteger()Decode the next ASN.1 element as a bit string where the value is a ASN.1 INTEGER.- Returns:
- a
BigIntegerdecoded from the bit string - Throws:
ASN1Exception- if the next element is not a bit string or its value is not an integer
-
decodeBitStringAsString
Decode the next ASN.1 element as a bit string.- Returns:
- the decoded bit string as a binary string, with any unused bits removed
- Throws:
ASN1Exception- if the next element is not a bit string
-
decodePrintableString
Decode the next ASN.1 element as a PrintableString.- Returns:
- the decoded PrintableString as a string
- Throws:
ASN1Exception- if the next element is not a PrintableString
-
decodePrintableStringAsBytes
Decode the next ASN.1 element as a PrintableString.- Returns:
- the decoded PrintableString as a byte array
- Throws:
ASN1Exception- if the next element is not a PrintableString
-
decodeUniversalString
Decode the next ASN.1 element as an UniversalString.- Returns:
- the decoded UniversalString as a string
- Throws:
ASN1Exception- if the next element is not a UniversalStringUnsupportedOperationException- if this implementation does not provide this method
-
decodeUniversalStringAsBytes
Decode the next ASN.1 element as an UniversalString.- Returns:
- the decoded UniversalString as a byte array
- Throws:
ASN1Exception- if the next element is not a UniversalStringUnsupportedOperationException- if this implementation does not provide this method
-
decodeUtf8String
Decode the next ASN.1 element as an UTF8String.- Returns:
- the decoded UTF8String as a string
- Throws:
ASN1Exception- if the next element is not a UTF8StringUnsupportedOperationException- if this implementation does not provide this method
-
decodeUtf8StringAsBytes
Decode the next ASN.1 element as an UTF8String.- Returns:
- the decoded UTF8String as a byte array
- Throws:
ASN1Exception- if the next element is not a UTF8StringUnsupportedOperationException- if this implementation does not provide this method
-
decodeBMPString
Decode the next ASN.1 element as an BMPString.- Returns:
- the decoded BMPString as a string
- Throws:
ASN1Exception- if the next element is not a BMPStringUnsupportedOperationException- if this implementation does not provide this method
-
decodeBMPStringAsBytes
Decode the next ASN.1 element as an BMPString.- Returns:
- the decoded BMPString as a byte array
- Throws:
ASN1Exception- if the next element is not a BMPStringUnsupportedOperationException- if this implementation does not provide this method
-
decodeObjectIdentifier
Decode the next ASN.1 element as an object identifier.- Returns:
- the object identifier as a string
- Throws:
ASN1Exception- if the next element is not a bit string
-
decodeInteger
BigInteger decodeInteger()Decode the next ASN.1 element as an integer.- Returns:
- an integer decoded from the next element
- Throws:
ASN1Exception- if the next element is not an integer
-
decodeNull
Decode the next ASN.1 element as a null element.- Throws:
ASN1Exception- if the next element is not null
-
decodeImplicit
void decodeImplicit(int number) Indicate that the next ASN.1 element has the given implicit, context-specific tag.- Parameters:
number- the tag number for the implicit tag
-
decodeImplicit
void decodeImplicit(int clazz, int number) Indicate that the next ASN.1 element has the given implicit tag.- Parameters:
clazz- the class for the implicit tagnumber- the tag number for the implicit tag
-
decodeBoolean
Decode the next ASN.1 element as a boolean value.- Returns:
- the decoded boolean value
- Throws:
ASN1Exception- if the next element is not a boolean value- Since:
- 1.2.0
-
isNextType
boolean isNextType(int clazz, int number, boolean isConstructed) Determine if the type of the next ASN.1 element matches the given type without actually decoding the next element. This method can be used to determine if an optional ASN.1 value has been included in the encoding or not.- Parameters:
clazz- the tag class to match againstnumber- the tag number to match againstisConstructed- whether or not the next element should be constructed- Returns:
trueif the type of the next ASN.1 element matches the given type andfalseotherwise
-
peekType
Retrieve the type of the next ASN.1 element without actually decoding the next element.- Returns:
- the type of the next ASN.1 element
- Throws:
ASN1Exception- if an error occurs while determining the type of the next element
-
skipElement
Skip over the next ASN.1 element.- Throws:
ASN1Exception- if the next element cannot be skipped
-
hasNextElement
boolean hasNextElement()Determine if there is at least one more ASN.1 element that can be read. If called while decoding a constructed element (i.e., while decoding a sequence, set, or explicitly tagged element), this method will return whether the constructed element has at least one more ASN.1 element that can be read. Otherwise, this method will return whether at least one more ASN.1 element can be read from the input stream.- Returns:
trueif there is at least one more ASN.1 element that can be read andfalseotherwise
-
drainElementValue
Drain the value bytes from the next ASN.1 element.- Returns:
- the value bytes from the next ASN.1 element, as a byte array
- Throws:
ASN1Exception- if the value bytes from the next ASN.1 element cannot be obtained
-
drainElement
Drain all of the bytes from the next ASN.1 element.- Returns:
- all of the bytes from the next ASN.1 element
- Throws:
ASN1Exception- if the bytes from the next ASN.1 element cannot be obtained
-
drain
byte[] drain()Drain all of the remaining bytes from the input stream.- Returns:
- all of the remaining bytes from the input stream
-