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
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.BigInteger
decodeBitStringAsInteger()
Decode the next ASN.1 element as a bit string where the value is a ASN.1 INTEGER.String
decodeBitStringAsString()
Decode the next ASN.1 element as a bit string.default String
decodeBMPString()
Decode the next ASN.1 element as an BMPString.default byte[]
decodeBMPStringAsBytes()
Decode the next ASN.1 element as an BMPString.boolean
decodeBoolean()
Decode the next ASN.1 element as a boolean value.String
decodeIA5String()
Decode the next ASN.1 element as an IA5 string.byte[]
decodeIA5StringAsBytes()
Decode the next ASN.1 element as an IA5 string.void
decodeImplicit(int number)
Indicate that the next ASN.1 element has the given implicit, context-specific tag.void
decodeImplicit(int clazz, int number)
Indicate that the next ASN.1 element has the given implicit tag.BigInteger
decodeInteger()
Decode the next ASN.1 element as an integer.void
decodeNull()
Decode the next ASN.1 element as a null element.String
decodeObjectIdentifier()
Decode the next ASN.1 element as an object identifier.byte[]
decodeOctetString()
Decode the next ASN.1 element as an octet string.String
decodeOctetStringAsString()
Decode the next ASN.1 element as an octet string.String
decodeOctetStringAsString(String charSet)
Decode the next ASN.1 element as an octet string.String
decodePrintableString()
Decode the next ASN.1 element as a PrintableString.byte[]
decodePrintableStringAsBytes()
Decode the next ASN.1 element as a PrintableString.default String
decodeUniversalString()
Decode the next ASN.1 element as an UniversalString.default byte[]
decodeUniversalStringAsBytes()
Decode the next ASN.1 element as an UniversalString.default String
decodeUtf8String()
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.void
endExplicit()
Advance to the end of an explicitly tagged element.void
endSequence()
Advance to the end of a sequence.void
endSet()
Advance to the end of a set.void
endSetOf()
Advance to the end of a "set of" element.boolean
hasNextElement()
Determine if there is at least one more ASN.1 element that can be read.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.int
peekType()
Retrieve the type of the next ASN.1 element without actually decoding the next element.void
skipElement()
Skip over the next ASN.1 element.void
startExplicit(int number)
Start decoding an ASN.1 explicitly tagged element.void
startExplicit(int clazz, int number)
Start decoding an ASN.1 explicitly tagged element.void
startSequence()
Start decoding an ASN.1 sequence.void
startSet()
Start decoding an ASN.1 set.void
startSetOf()
Start decoding an ASN.1 "set of" element.
-
-
-
Method Detail
-
startSequence
void startSequence() throws ASN1Exception
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
void endSequence() throws ASN1Exception
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
void startSet() throws ASN1Exception
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
void endSet() throws ASN1Exception
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
void startSetOf() throws ASN1Exception
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
void endSetOf() throws ASN1Exception
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
void startExplicit(int number) throws ASN1Exception
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
void startExplicit(int clazz, int number) throws ASN1Exception
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
void endExplicit() throws ASN1Exception
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
byte[] decodeOctetString() throws ASN1Exception
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
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 ASN1Exception
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
byte[] decodeBitString() throws ASN1Exception
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
BigInteger
decoded 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 ASN1Exception
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
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 ASN1Exception
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
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 ASN1Exception
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
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 ASN1Exception
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
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 ASN1Exception
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
boolean decodeBoolean() throws ASN1Exception
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:
true
if the type of the next ASN.1 element matches the given type andfalse
otherwise
-
peekType
int peekType() throws ASN1Exception
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
void skipElement() throws ASN1Exception
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:
true
if there is at least one more ASN.1 element that can be read andfalse
otherwise
-
drainElementValue
byte[] drainElementValue() throws ASN1Exception
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
byte[] drainElement() throws ASN1Exception
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
-
-