Top Description Fields Constructors Methods
org.bouncycastle.asn1

public abstract Class ASN1OctetString

extends ASN1Primitive
implements ASN1OctetStringParser
Class Inheritance
All Implemented Interfaces
org.bouncycastle.asn1.ASN1OctetStringParser, org.bouncycastle.asn1.InMemoryRepresentable, org.bouncycastle.asn1.ASN1Encodable
Known Direct Subclasses
org.bouncycastle.asn1.DEROctetString, org.bouncycastle.asn1.BEROctetString
Imports
java.io.ByteArrayInputStream, .IOException, .InputStream, org.bouncycastle.util.Arrays, .Strings, org.bouncycastle.util.encoders.Hex

Abstract base for the ASN.1 OCTET STRING data type

This supports BER, and DER forms of the data.

DER form is always primitive single OCTET STRING, while BER support includes the constructed forms.

X.690

8: Basic encoding rules

8.7 Encoding of an octetstring value

8.7.1 The encoding of an octetstring value shall be either primitive or constructed at the option of the sender.

NOTE — Where it is necessary to transfer part of an octet string before the entire OCTET STRING is available, the constructed encoding is used.

8.7.2 The primitive encoding contains zero, one or more contents octets equal in value to the octets in the data value, in the order they appear in the data value, and with the most significant bit of an octet of the data value aligned with the most significant bit of an octet of the contents octets.

8.7.3 The contents octets for the constructed encoding shall consist of zero, one, or more encodings.

NOTE — Each such encoding includes identifier, length, and contents octets, and may include end-of-contents octets if it is constructed.

8.7.3.1 To encode an octetstring value in this way, it is segmented. Each segment shall consist of a series of consecutive octets of the value. There shall be no significance placed on the segment boundaries.

NOTE — A segment may be of size zero, i.e. contain no octets.

8.7.3.2 Each encoding in the contents octets shall represent a segment of the overall octetstring, the encoding arising from a recursive application of this subclause. In this recursive application, each segment is treated as if it were a octetstring value. The encodings of the segments shall appear in the contents octets in the order in which their octets appear in the overall value.

NOTE 1 — As a consequence of this recursion, each encoding in the contents octets may itself be primitive or constructed. However, such encodings will usually be primitive.
NOTE 2 — In particular, the tags in the contents octets are always universal class, number 4.

9: Canonical encoding rules

9.1 Length forms

If the encoding is constructed, it shall employ the indefinite-length form. If the encoding is primitive, it shall include the fewest length octets necessary. [Contrast with 8.1.3.2 b).]

9.2 String encoding forms

BIT STRING, OCTET STRING,and restricted character string values shall be encoded with a primitive encoding if they would require no more than 1000 contents octets, and as a constructed encoding otherwise. The string fragments contained in the constructed encoding shall be encoded with a primitive encoding. The encoding of each fragment, except possibly the last, shall have 1000 contents octets. (Contrast with 8.21.6.)

10: Distinguished encoding rules

10.1 Length forms The definite form of length encoding shall be used, encoded in the minimum number of octets. [Contrast with 8.1.3.2 b).]

10.2 String encoding forms For BIT STRING, OCTET STRING and restricted character string types, the constructed form of encoding shall not be used. (Contrast with 8.21.6.)

Field Summary

Modifier and TypeField and Description
pack-priv static final byte[]
pack-priv byte[]
pack-priv static final ASN1UniversalType

Constructor Summary

AccessConstructor and Description
public
ASN1OctetString(byte[]
the octets making up the octet string.
string
)

Base constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
asn1Equals(ASN1Primitive o)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Equality (similarity) comparison for two ASN1Primitive objects.
pack-priv static ASN1OctetString
createPrimitive(byte[] contents)

public static ASN1OctetString
getInstance(ASN1TaggedObject
the tagged object holding the object we want.
taggedObject
,
boolean
true if the object is meant to be explicitly tagged false otherwise.
explicit
)

return an Octet String from a tagged object.

public static ASN1OctetString
getInstance(Object
the object we want converted.
obj
)

return an Octet String from the given object.

public ASN1Primitive
getLoadedObject()

Implements org.bouncycastle.asn1.InMemoryRepresentable.getLoadedObject.

Get the in-memory representation of the ASN.1 object.
public byte[]

Returns:

the byte[] representing the OCTET STRING's content.
getOctets
()

Return the content of the OCTET STRING as a byte array.

public int
public InputStream

Returns:

an InputStream representing the OCTET STRING's content.
getOctetStream
()

Implements org.bouncycastle.asn1.ASN1OctetStringParser.getOctetStream.

Return the content of the OCTET STRING as an InputStream.
public int
hashCode()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.hashCode.

Returns a hash code value for the object.
public ASN1OctetStringParser

Returns:

a parser based on this OCTET STRING
parser
()

Return the parser associated with this object.

pack-priv ASN1Primitive
toDERObject()

Overrides org.bouncycastle.asn1.ASN1Primitive.toDERObject.

Return the current object as one which encodes using Distinguished Encoding Rules.
pack-priv ASN1Primitive
toDLObject()

Overrides org.bouncycastle.asn1.ASN1Primitive.toDLObject.

Return the current object as one which encodes using Definite Length encoding.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.bouncycastle.asn1.ASN1Primitive:
encodeencodeConstructedencodedLengthencodeToencodeToequalsequalsequalsfromByteArraytoASN1Primitive

Field Detail

EMPTY_OCTETSback to summary
pack-priv static final byte[] EMPTY_OCTETS
stringback to summary
pack-priv byte[] string
TYPEback to summary
pack-priv static final ASN1UniversalType TYPE

Constructor Detail

ASN1OctetStringback to summary
public ASN1OctetString(byte[] string)

Base constructor.

Parameters
string:byte[]

the octets making up the octet string.

Method Detail

asn1Equalsback to summary
pack-priv boolean asn1Equals(ASN1Primitive o)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Doc from org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Equality (similarity) comparison for two ASN1Primitive objects.

createPrimitiveback to summary
pack-priv static ASN1OctetString createPrimitive(byte[] contents)
getInstanceback to summary
public static ASN1OctetString getInstance(ASN1TaggedObject taggedObject, boolean explicit)

return an Octet String from a tagged object.

Parameters
taggedObject:ASN1TaggedObject

the tagged object holding the object we want.

explicit:boolean

true if the object is meant to be explicitly tagged false otherwise.

Exceptions
IllegalArgumentException:
if the tagged object cannot be converted.
getInstanceback to summary
public static ASN1OctetString getInstance(Object obj)

return an Octet String from the given object.

Parameters
obj:Object

the object we want converted.

Exceptions
IllegalArgumentException:
if the object cannot be converted.
getLoadedObjectback to summary
public ASN1Primitive getLoadedObject()

Implements org.bouncycastle.asn1.InMemoryRepresentable.getLoadedObject.

Doc from org.bouncycastle.asn1.InMemoryRepresentable.getLoadedObject.

Get the in-memory representation of the ASN.1 object.

Returns:ASN1Primitive

an ASN1Primitive representing the loaded object.

getOctetsback to summary
public byte[] getOctets()

Return the content of the OCTET STRING as a byte array.

Returns:byte[]

the byte[] representing the OCTET STRING's content.

getOctetsLengthback to summary
public int getOctetsLength()
getOctetStreamback to summary
public InputStream getOctetStream()

Implements org.bouncycastle.asn1.ASN1OctetStringParser.getOctetStream.

Return the content of the OCTET STRING as an InputStream.

Returns:InputStream

an InputStream representing the OCTET STRING's content.

hashCodeback to summary
public int hashCode()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

parserback to summary
public ASN1OctetStringParser parser()

Return the parser associated with this object.

Returns:ASN1OctetStringParser

a parser based on this OCTET STRING

toDERObjectback to summary
pack-priv ASN1Primitive toDERObject()

Overrides org.bouncycastle.asn1.ASN1Primitive.toDERObject.

Doc from org.bouncycastle.asn1.ASN1Primitive.toDERObject.

Return the current object as one which encodes using Distinguished Encoding Rules.

Returns:ASN1Primitive

a DER version of this.

toDLObjectback to summary
pack-priv ASN1Primitive toDLObject()

Overrides org.bouncycastle.asn1.ASN1Primitive.toDLObject.

Doc from org.bouncycastle.asn1.ASN1Primitive.toDLObject.

Return the current object as one which encodes using Definite Length encoding.

Returns:ASN1Primitive

a DL version of this.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.