Package org.wildfly.security.asn1
Class DEREncoder
- java.lang.Object
-
- org.wildfly.security.asn1.DEREncoder
-
- All Implemented Interfaces:
Flushable,ASN1Encoder
public class DEREncoder extends Object implements ASN1Encoder
A class used to encode ASN.1 values using the Distinguished Encoding Rules (DER), as specified in ITU-T X.690.- Author:
- Farah Juma
-
-
Constructor Summary
Constructors Constructor Description DEREncoder()Create a DER encoder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidencodeBitString(byte[] str)Encode an ASN.1 bit string value.voidencodeBitString(byte[] str, int numUnusedBits)Encode an ASN.1 bit string value.voidencodeBitString(String binaryStr)Encode an ASN.1 bit string value.voidencodeBitString(BigInteger integer)Encode an ASN.1 bit string where the value represents the binary form of the giveninteger.voidencodeBitString(BitSet bitSet)Encode an ASN.1 bit string value.voidencodeBitString(EnumSet<?> enumSet)Encode an enum set as an ASN.1 bit string, with each ordinal value of the set representing a single bit.voidencodeBMPString(String str)Encode an ASN.1 BMPString string value.voidencodeBoolean(boolean value)Encode an ASN.1booleanvalue.voidencodeGeneralizedTime(ZonedDateTime time)Encode an ASN.1 GeneralizedTime type.voidencodeIA5String(byte[] str)Encode an ASN.1 IA5 string value.voidencodeIA5String(String str)Encode an ASN.1 IA5 string value.voidencodeImplicit(int number)Indicate that the next encode operation should encode an ASN.1 value using the given implicit, context-specific tag.voidencodeImplicit(int clazz, int number)Indicate that the next encode operation should encode an ASN.1 value using the given implicit tag.voidencodeInteger(BigInteger integer)Encode an ASN.1integervalue.voidencodeNull()Encode an ASN.1 null value.voidencodeObjectIdentifier(String objectIdentifier)Encode an ASN.1 object identifier value.voidencodeOctetString(byte[] str)Encode an ASN.1 octet string value.voidencodeOctetString(String str)Encode an ASN.1 octet string value.voidencodePrintableString(byte[] str)Encode an ASN.1 printable string value.voidencodePrintableString(String str)Encode an ASN.1 printable string value.voidencodeUniversalString(String str)Encode an ASN.1 UniversalString string value.voidencodeUTF8String(String str)Encode an ASN.1 UTF8String string value.voidendExplicit()Finish encoding an ASN.1 explicitly tagged element.voidendSequence()Finish encoding an ASN.1 sequence.voidendSet()Finish encoding an ASN.1 set.voidendSetOf()Finish encoding an ASN.1 "set of" element.voidflush()Flush the encoder, writing any saved ASN.1 encoded values to the target destination.byte[]getEncoded()Get the ASN.1 encoded bytes.voidstartExplicit(int number)Start encoding an ASN.1 explicitly tagged element.voidstartExplicit(int clazz, int number)Start encoding an ASN.1 explicitly tagged element.voidstartSequence()Start encoding an ASN.1 sequence.voidstartSet()Start encoding an ASN.1 set.voidstartSetOf()Start encoding an ASN.1 "set of" element.voidwriteEncoded(byte[] encoded)Write an already encoded ASN.1 value to the target destination.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.wildfly.security.asn1.ASN1Encoder
encodeInteger
-
-
-
-
Method Detail
-
startSequence
public void startSequence()
Description copied from interface:ASN1EncoderStart encoding an ASN.1 sequence. All subsequent encode operations will be part of this sequence untilASN1Encoder.endSequence()is called.- Specified by:
startSequencein interfaceASN1Encoder
-
startSet
public void startSet()
Description copied from interface:ASN1EncoderStart encoding an ASN.1 set. All subsequent encode operations will be part of this set untilASN1Encoder.endSet()is called.- Specified by:
startSetin interfaceASN1Encoder
-
startSetOf
public void startSetOf()
Description copied from interface:ASN1EncoderStart encoding an ASN.1 "set of" element. All subsequent encode operations will be part of this set untilASN1Encoder.endSetOf()is called.- Specified by:
startSetOfin interfaceASN1Encoder
-
startExplicit
public void startExplicit(int number)
Description copied from interface:ASN1EncoderStart encoding an ASN.1 explicitly tagged element. All subsequent encode operations will be part of this explicitly tagged element untilASN1Encoder.endExplicit()is called.- Specified by:
startExplicitin interfaceASN1Encoder- Parameters:
number- the tag number for the explicit, context-specific tag
-
startExplicit
public void startExplicit(int clazz, int number)Description copied from interface:ASN1EncoderStart encoding an ASN.1 explicitly tagged element. All subsequent encode operations will be part of this explicitly tagged element untilASN1Encoder.endExplicit()is called.- Specified by:
startExplicitin interfaceASN1Encoder- Parameters:
clazz- the class for the explicit tagnumber- the tag number for the explicit tag
-
endSequence
public void endSequence() throws IllegalStateExceptionDescription copied from interface:ASN1EncoderFinish encoding an ASN.1 sequence.- Specified by:
endSequencein interfaceASN1Encoder- Throws:
IllegalStateException- if there is no sequence to end
-
endExplicit
public void endExplicit() throws IllegalStateExceptionDescription copied from interface:ASN1EncoderFinish encoding an ASN.1 explicitly tagged element.- Specified by:
endExplicitin interfaceASN1Encoder- Throws:
IllegalStateException- if there is no explicitly tagged element to end
-
endSet
public void endSet() throws IllegalStateExceptionDescription copied from interface:ASN1EncoderFinish encoding an ASN.1 set.- Specified by:
endSetin interfaceASN1Encoder- Throws:
IllegalStateException- if there is no set to end
-
endSetOf
public void endSetOf() throws IllegalStateExceptionDescription copied from interface:ASN1EncoderFinish encoding an ASN.1 "set of" element.- Specified by:
endSetOfin interfaceASN1Encoder- Throws:
IllegalStateException- if there is no set to end
-
encodeOctetString
public void encodeOctetString(String str)
Description copied from interface:ASN1EncoderEncode an ASN.1 octet string value.- Specified by:
encodeOctetStringin interfaceASN1Encoder- Parameters:
str- the octet string to encode
-
encodeOctetString
public void encodeOctetString(byte[] str)
Description copied from interface:ASN1EncoderEncode an ASN.1 octet string value.- Specified by:
encodeOctetStringin interfaceASN1Encoder- Parameters:
str- the byte array containing the octet string to encode
-
encodeIA5String
public void encodeIA5String(String str)
Description copied from interface:ASN1EncoderEncode an ASN.1 IA5 string value.- Specified by:
encodeIA5Stringin interfaceASN1Encoder- Parameters:
str- the IA5 string to encode
-
encodeIA5String
public void encodeIA5String(byte[] str)
Description copied from interface:ASN1EncoderEncode an ASN.1 IA5 string value.- Specified by:
encodeIA5Stringin interfaceASN1Encoder- Parameters:
str- the byte array containing IA5 string to encode
-
encodePrintableString
public void encodePrintableString(byte[] str)
Description copied from interface:ASN1EncoderEncode an ASN.1 printable string value.- Specified by:
encodePrintableStringin interfaceASN1Encoder- Parameters:
str- the byte array containing the printable string to encode
-
encodePrintableString
public void encodePrintableString(String str)
Description copied from interface:ASN1EncoderEncode an ASN.1 printable string value.- Specified by:
encodePrintableStringin interfaceASN1Encoder- Parameters:
str- the printable string to encode
-
encodeUTF8String
public void encodeUTF8String(String str)
Description copied from interface:ASN1EncoderEncode an ASN.1 UTF8String string value.- Specified by:
encodeUTF8Stringin interfaceASN1Encoder- Parameters:
str- the string to encode
-
encodeBMPString
public void encodeBMPString(String str)
Description copied from interface:ASN1EncoderEncode an ASN.1 BMPString string value.- Specified by:
encodeBMPStringin interfaceASN1Encoder- Parameters:
str- the string to encode
-
encodeUniversalString
public void encodeUniversalString(String str)
Description copied from interface:ASN1EncoderEncode an ASN.1 UniversalString string value.- Specified by:
encodeUniversalStringin interfaceASN1Encoder- Parameters:
str- the string to encode
-
encodeBitString
public void encodeBitString(byte[] str)
Description copied from interface:ASN1EncoderEncode an ASN.1 bit string value.- Specified by:
encodeBitStringin interfaceASN1Encoder- Parameters:
str- the byte array containing the bit string to encode (all bits in the bit string will be used)
-
encodeBitString
public void encodeBitString(byte[] str, int numUnusedBits)Description copied from interface:ASN1EncoderEncode an ASN.1 bit string value.- Specified by:
encodeBitStringin interfaceASN1Encoder- Parameters:
str- the byte array containing the bit string to encodenumUnusedBits- the number of unused bits in the byte array
-
encodeBitString
public void encodeBitString(EnumSet<?> enumSet)
Description copied from interface:ASN1EncoderEncode an enum set as an ASN.1 bit string, with each ordinal value of the set representing a single bit.- Specified by:
encodeBitStringin interfaceASN1Encoder- Parameters:
enumSet- the enum set (must not benull)
-
encodeBitString
public void encodeBitString(BitSet bitSet)
Description copied from interface:ASN1EncoderEncode an ASN.1 bit string value.- Specified by:
encodeBitStringin interfaceASN1Encoder- Parameters:
bitSet- the bit set (must not benull)
-
encodeBitString
public void encodeBitString(String binaryStr)
Description copied from interface:ASN1EncoderEncode an ASN.1 bit string value.- Specified by:
encodeBitStringin interfaceASN1Encoder- Parameters:
binaryStr- the bit string to encode, as a binary string
-
encodeBitString
public void encodeBitString(BigInteger integer)
Description copied from interface:ASN1EncoderEncode an ASN.1 bit string where the value represents the binary form of the giveninteger.- Specified by:
encodeBitStringin interfaceASN1Encoder- Parameters:
integer- the integer to encode as a binary string
-
encodeGeneralizedTime
public void encodeGeneralizedTime(ZonedDateTime time)
Description copied from interface:ASN1EncoderEncode an ASN.1 GeneralizedTime type.- Specified by:
encodeGeneralizedTimein interfaceASN1Encoder- Parameters:
time- the time to encode (must not benull)
-
encodeObjectIdentifier
public void encodeObjectIdentifier(String objectIdentifier) throws ASN1Exception
Description copied from interface:ASN1EncoderEncode an ASN.1 object identifier value.- Specified by:
encodeObjectIdentifierin interfaceASN1Encoder- Parameters:
objectIdentifier- the object identifier to encode- Throws:
ASN1Exception- if the given object identifier is invalid
-
encodeNull
public void encodeNull()
Description copied from interface:ASN1EncoderEncode an ASN.1 null value.- Specified by:
encodeNullin interfaceASN1Encoder
-
encodeImplicit
public void encodeImplicit(int number)
Description copied from interface:ASN1EncoderIndicate that the next encode operation should encode an ASN.1 value using the given implicit, context-specific tag.- Specified by:
encodeImplicitin interfaceASN1Encoder- Parameters:
number- the tag number for the implicit, context-specific tag
-
encodeImplicit
public void encodeImplicit(int clazz, int number)Description copied from interface:ASN1EncoderIndicate that the next encode operation should encode an ASN.1 value using the given implicit tag.- Specified by:
encodeImplicitin interfaceASN1Encoder- Parameters:
clazz- the class for the implicit tagnumber- the tag number for the implicit tag
-
encodeBoolean
public void encodeBoolean(boolean value)
Description copied from interface:ASN1EncoderEncode an ASN.1booleanvalue.- Specified by:
encodeBooleanin interfaceASN1Encoder- Parameters:
value- the boolean to encode
-
encodeInteger
public void encodeInteger(BigInteger integer)
Description copied from interface:ASN1EncoderEncode an ASN.1integervalue.- Specified by:
encodeIntegerin interfaceASN1Encoder- Parameters:
integer- the integer to encode
-
writeEncoded
public void writeEncoded(byte[] encoded)
Description copied from interface:ASN1EncoderWrite an already encoded ASN.1 value to the target destination.- Specified by:
writeEncodedin interfaceASN1Encoder- Parameters:
encoded- the encoded ASN.1 value to write
-
flush
public void flush()
Description copied from interface:ASN1EncoderFlush the encoder, writing any saved ASN.1 encoded values to the target destination. Any unfinished sequences or sets will be ended.- Specified by:
flushin interfaceASN1Encoder- Specified by:
flushin interfaceFlushable
-
getEncoded
public byte[] getEncoded()
Description copied from interface:ASN1EncoderGet the ASN.1 encoded bytes.- Specified by:
getEncodedin interfaceASN1Encoder- Returns:
- the ASN.1 encoded bytes
-
-