Package org.mozilla.jss.asn1
Class ANY
java.lang.Object
org.mozilla.jss.asn1.ANY
- All Implemented Interfaces:
ASN1Value
Represents an ASN.1
ANY
value. An ANY is just an arbitrary
ASN.1 value. It can be thought of as the simplest implementation of the
ASN1Value
interface. Although they can be created
from scratch (from raw BER), instances of ANY
are usually
found after decoding
with a template that has an ANY
field.
An ANY
supports extracting the BER encoding, or decoding
with a different template.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A class for decodingANY
values from BER. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
Strips out the header and returns just the contents octets of the encoding.private byte[]
private ASN1Header
private Tag
private static ANY.Template
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecodeWith
(ASN1Template template) Decodes this ANY using the given template.decodeWith
(Tag implicitTag, ASN1Template template) Decodes this ANY using the given template.void
encode
(OutputStream ostream) Write this value's DER encoding to an output stream using its own base tag.void
encode
(Tag implicitTag, OutputStream ostream) Write this value's DER encoding to an output stream using an implicit tag.void
encodeWithAlternateTag
(Tag alternateTag, OutputStream ostream) Extracts the contents from the ANY and encodes them with the provided tag.byte[]
byte[]
Returns the complete encoding of header and contents, as passed into the constructor or read from a BER input stream.Returns the ASN.1 header from the encoding.getTag()
Returns the tag of this value.static ANY.Template
Returns a singleton instance of a decoding template.
-
Field Details
-
encoded
private byte[] encoded -
tag
-
header
-
contents
private byte[] contentsStrips out the header and returns just the contents octets of the encoding. -
templateInstance
-
-
Constructor Details
-
ANY
Creates an ANY value, which is just a generic ASN.1 value. This method is provided for efficiency if the tag is already known, so that we don't have to parse the encoding for it.- Parameters:
tag
- The tag of this value. It must be the same as the actual tag contained in the encoding.encoded
- The complete BER encoding of this value, including tag, form, length, and contents.
-
ANY
Creates an ANY value, which is just a generic ASN.1 value.- Parameters:
encoded
- The complete BER encoding of this value, including tag, form, length, and contents.- Throws:
InvalidBERException
- If there is an invalid BER encoding.
-
-
Method Details
-
getTag
Returns the tag of this value. -
getEncoded
public byte[] getEncoded()Returns the complete encoding of header and contents, as passed into the constructor or read from a BER input stream.- Returns:
- Encoded header and contents.
-
getHeader
Returns the ASN.1 header from the encoding.- Returns:
- ASN.1 header.
- Throws:
InvalidBERException
- If there is an invalid BER encoding.IOException
- If other error occurred.
-
getContents
- Throws:
InvalidBERException
-
encode
Description copied from interface:ASN1Value
Write this value's DER encoding to an output stream using its own base tag.- Specified by:
encode
in interfaceASN1Value
- Parameters:
ostream
- Output stream.- Throws:
IOException
- If an error occurred.
-
decodeWith
Decodes this ANY using the given template. This is useful if you originally decoded something as an ANY because you didn't know what it was, but now you know what it is supposed to be.- Parameters:
template
- The template to use to decode this ANY.- Returns:
- The output of the given template when it is fed the encoding of this ANY.
- Throws:
InvalidBERException
- If there is an invalid BER encoding.
-
decodeWith
public ASN1Value decodeWith(Tag implicitTag, ASN1Template template) throws IOException, InvalidBERException Decodes this ANY using the given template. This is useful if you originally decoded something as an ANY because you didn't know what it was, but now you know what it is supposed to be.- Parameters:
implicitTag
- The implicit tag for the encoding.template
- The template to use to decode this ANY.- Returns:
- The output of the given template when it is fed the encoding of this ANY.
- Throws:
InvalidBERException
- If there is an invalid BER encoding.IOException
- If other error occurred.
-
encode
Description copied from interface:ASN1Value
Write this value's DER encoding to an output stream using an implicit tag.- Specified by:
encode
in interfaceASN1Value
- Parameters:
implicitTag
- This parameter is ignored, because ANY values cannot have implicit tags.ostream
- Output stream.- Throws:
IOException
- If an error occurred.
-
encodeWithAlternateTag
public void encodeWithAlternateTag(Tag alternateTag, OutputStream ostream) throws IOException, InvalidBERException Extracts the contents from the ANY and encodes them with the provided tag.- Parameters:
alternateTag
- Alternate tag.ostream
- Output stream.- Throws:
InvalidBERException
- If there is an invalid BER encoding.IOException
- If other error occurred.
-
getTemplate
Returns a singleton instance of a decoding template.- Returns:
- Decoding template.
-