Package org.wildfly.security.asn1
Interface ASN1Decoder
-
- All Known Implementing Classes:
DERDecoder
public interface ASN1DecoderAn interface for decoding ASN.1 encoded values from an input stream.- Author:
- Farah Juma
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description byte[]decodeBitString()Decode the next ASN.1 element as a bit string.BigIntegerdecodeBitStringAsInteger()Decode the next ASN.1 element as a bit string where the value is a ASN.1 INTEGER.StringdecodeBitStringAsString()Decode the next ASN.1 element as a bit string.default StringdecodeBMPString()Decode the next ASN.1 element as an BMPString.default byte[]decodeBMPStringAsBytes()Decode the next ASN.1 element as an BMPString.booleandecodeBoolean()Decode the next ASN.1 element as a boolean value.StringdecodeIA5String()Decode the next ASN.1 element as an IA5 string.byte[]decodeIA5StringAsBytes()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.BigIntegerdecodeInteger()Decode the next ASN.1 element as an integer.voiddecodeNull()Decode the next ASN.1 element as a null element.StringdecodeObjectIdentifier()Decode the next ASN.1 element as an object identifier.byte[]decodeOctetString()Decode the next ASN.1 element as an octet string.StringdecodeOctetStringAsString()Decode the next ASN.1 element as an octet string.StringdecodeOctetStringAsString(String charSet)Decode the next ASN.1 element as an octet string.StringdecodePrintableString()Decode the next ASN.1 element as a PrintableString.byte[]decodePrintableStringAsBytes()Decode the next ASN.1 element as a PrintableString.default StringdecodeUniversalString()Decode the next ASN.1 element as an UniversalString.default byte[]decodeUniversalStringAsBytes()Decode the next ASN.1 element as an UniversalString.default StringdecodeUtf8String()Decode the next ASN.1 element as an UTF8String.default byte[]decodeUtf8StringAsBytes()Decode the next ASN.1 element as an UTF8String.byte[]drain()Drain all of the remaining bytes from the input stream.byte[]drainElement()Drain all of the bytes from the next ASN.1 element.byte[]drainElementValue()Drain the value bytes from the next ASN.1 element.voidendExplicit()Advance to the end of an explicitly tagged element.voidendSequence()Advance to the end of a sequence.voidendSet()Advance to the end of a set.voidendSetOf()Advance to the end of a "set of" element.booleanhasNextElement()Determine 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.voidskipElement()Skip 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.voidstartSequence()Start decoding an ASN.1 sequence.voidstartSet()Start decoding an ASN.1 set.voidstartSetOf()Start decoding an ASN.1 "set of" element.
-
-
-
Method Detail
-
startSequence
void startSequence() throws ASN1ExceptionStart 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
void endSequence() throws ASN1ExceptionAdvance 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
void startSet() throws ASN1ExceptionStart 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
void endSet() throws ASN1ExceptionAdvance 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
void startSetOf() throws ASN1ExceptionStart 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
void endSetOf() throws ASN1ExceptionAdvance 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
void startExplicit(int number) throws ASN1ExceptionStart 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
void startExplicit(int clazz, int number) throws ASN1ExceptionStart 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
void endExplicit() throws ASN1ExceptionAdvance 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
byte[] decodeOctetString() throws ASN1ExceptionDecode 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
String decodeOctetStringAsString() throws ASN1Exception
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
String decodeOctetStringAsString(String charSet) throws ASN1Exception
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
String decodeIA5String() throws ASN1Exception
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
byte[] decodeIA5StringAsBytes() throws ASN1ExceptionDecode 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
byte[] decodeBitString() throws ASN1ExceptionDecode 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
String decodeBitStringAsString() throws ASN1Exception
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
String decodePrintableString() throws ASN1Exception
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
byte[] decodePrintableStringAsBytes() throws ASN1ExceptionDecode 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
default String decodeUniversalString() throws ASN1Exception
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
default byte[] decodeUniversalStringAsBytes() throws ASN1ExceptionDecode 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
default String decodeUtf8String() throws ASN1Exception
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
default byte[] decodeUtf8StringAsBytes() throws ASN1ExceptionDecode 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
default String decodeBMPString() throws ASN1Exception
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
default byte[] decodeBMPStringAsBytes() throws ASN1ExceptionDecode 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
String decodeObjectIdentifier() throws ASN1Exception
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
void decodeNull() throws ASN1ExceptionDecode 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
boolean decodeBoolean() throws ASN1ExceptionDecode 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
int peekType() throws ASN1ExceptionRetrieve 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
void skipElement() throws ASN1ExceptionSkip 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
byte[] drainElementValue() throws ASN1ExceptionDrain 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
byte[] drainElement() throws ASN1ExceptionDrain 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
-
-