Top Description Fields Constructors Methods
org.bouncycastle.asn1

public abstract Class ASN1Set

extends ASN1Primitive
implements Iterable<ASN1Encodable>
Class Inheritance
All Implemented Interfaces
org.bouncycastle.util.Iterable, java.lang.Iterable
Known Direct Subclasses
org.bouncycastle.asn1.DLSet, org.bouncycastle.asn1.DERSet, org.bouncycastle.asn1.BERSet
Imports
java.io.IOException, java.util.Enumeration, .Iterator, .NoSuchElementException, org.bouncycastle.util.Arrays

ASN.1 SET and SET OF constructs.

Note

This does not know which syntax the set is! (The difference: ordering of SET elements or not ordering.)

DER form is always definite form length fields, while BER support uses indefinite form.

The CER form support does not exist.

X.690

8: Basic encoding rules

8.11 Encoding of a set value

8.11.1 The encoding of a set value shall be constructed

8.11.2 The contents octets shall consist of the complete encoding of a data value from each of the types listed in the ASN.1 definition of the set type, in an order chosen by the sender, unless the type was referenced with the keyword OPTIONAL or the keyword DEFAULT.

8.11.3 The encoding of a data value may, but need not, be present for a type which was referenced with the keyword OPTIONAL or the keyword DEFAULT.

NOTE — The order of data values in a set value is not significant, and places no constraints on the order during transfer

8.12 Encoding of a set-of value

8.12.1 The encoding of a set-of value shall be constructed.

8.12.2 The text of 8.10.2 applies: The contents octets shall consist of zero, one or more complete encodings of data values from the type listed in the ASN.1 definition.

8.12.3 The order of data values need not be preserved by the encoding and subsequent decoding.

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.3 Set components

The encodings of the component values of a set value shall appear in an order determined by their tags as specified in 8.6 of ITU-T Rec. X.680 | ISO/IEC 8824-1. Additionally, for the purposes of determining the order in which components are encoded when one or more component is an untagged choice type, each untagged choice type is ordered as though it has a tag equal to that of the smallest tag in that choice type or any untagged choice types nested within.

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.3 Set components

The encodings of the component values of a set value shall appear in an order determined by their tags as specified in 8.6 of ITU-T Rec. X.680 | ISO/IEC 8824-1.
NOTE — Where a component of the set is an untagged choice type, the location of that component in the ordering will depend on the tag of the choice component being encoded.

11: Restrictions on BER employed by both CER and DER

11.5 Set and sequence components with default value

The encoding of a set value or sequence value shall not include an encoding for any component value which is equal to its default value.

11.6 Set-of components

The encodings of the component values of a set-of value shall appear in ascending order, the encodings being compared as octet strings with the shorter components being padded at their trailing end with 0-octets.

NOTE — The padding octets are for comparison purposes only and do not appear in the encodings.

Field Summary

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

Constructor Summary

AccessConstructor and Description
protected
protected
ASN1Set(ASN1Encodable
object to be added to the SET.
element
)

Create a SET containing one object

protected
ASN1Set(ASN1EncodableVector
a vector of objects to make up the SET.
elementVector
,
boolean
true if should be sorted DER style, false otherwise.
doSort
)

Create a SET containing a vector of objects.

protected
ASN1Set(ASN1Encodable[]
an array of objects to make up the SET.
elements
,
boolean
true if should be sorted DER style, false otherwise.
doSort
)

Create a SET containing an array of objects.

pack-priv
ASN1Set(boolean isSorted, ASN1Encodable[] elements)

pack-priv
ASN1Set(ASN1Encodable[] elements, ASN1Encodable[] sortedElements)

Method Summary

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

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

Equality (similarity) comparison for two ASN1Primitive objects.
pack-priv boolean
encodeConstructed()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Return true if this objected is a CONSTRUCTED one, false otherwise.
private static byte[]
public static ASN1Set

Returns:

an ASN1Set instance, or null.
getInstance
(Object
the object we want converted.
obj
)

return an ASN1Set from the given object.

public static ASN1Set

Returns:

an ASN1Set instance.
getInstance
(ASN1TaggedObject
the tagged object.
taggedObject
,
boolean
true if the object is meant to be explicitly tagged false otherwise.
explicit
)

Return an ASN1 set from a tagged object.

public ASN1Encodable

Returns:

the object at the set position indicated by index.
getObjectAt
(int
the set number (starting at zero) of the object
index
)

return the object at the set position indicated by index.

public Enumeration<E>
public int
hashCode()

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

Returns a hash code value for the object.
public Iterator<ASN1Encodable>
iterator()

Implements org.bouncycastle.util.Iterable.iterator.

Returns an iterator over a set of elements of type T.
private static boolean
lessThanOrEqual(byte[] a, byte[] b)

return true if a <= b (arrays are assumed padded with zeros).

public ASN1SetParser
public int

Returns:

the number of objects in this set.
size
()

return the number of objects in this set.

private static void
public ASN1Encodable[]
pack-priv ASN1Primitive
toDERObject()

Overrides org.bouncycastle.asn1.ASN1Primitive.toDERObject.

Change current SET object to be encoded as DERSet.
pack-priv ASN1Primitive
toDLObject()

Overrides org.bouncycastle.asn1.ASN1Primitive.toDLObject.

Change current SET object to be encoded as DLSet.
public String
toString()

Overrides java.lang.Object.toString.

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

Field Detail

elementsback to summary
protected final ASN1Encodable[] elements
sortedElementsback to summary
protected ASN1Encodable[] sortedElements
TYPEback to summary
pack-priv static final ASN1UniversalType TYPE

Constructor Detail

ASN1Setback to summary
protected ASN1Set()
ASN1Setback to summary
protected ASN1Set(ASN1Encodable element)

Create a SET containing one object

Parameters
element:ASN1Encodable

object to be added to the SET.

ASN1Setback to summary
protected ASN1Set(ASN1EncodableVector elementVector, boolean doSort)

Create a SET containing a vector of objects.

Parameters
elementVector:ASN1EncodableVector

a vector of objects to make up the SET.

doSort:boolean

true if should be sorted DER style, false otherwise.

ASN1Setback to summary
protected ASN1Set(ASN1Encodable[] elements, boolean doSort)

Create a SET containing an array of objects.

Parameters
elements:ASN1Encodable[]

an array of objects to make up the SET.

doSort:boolean

true if should be sorted DER style, false otherwise.

ASN1Setback to summary
pack-priv ASN1Set(boolean isSorted, ASN1Encodable[] elements)
ASN1Setback to summary
pack-priv ASN1Set(ASN1Encodable[] elements, ASN1Encodable[] sortedElements)

Method Detail

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

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

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

Equality (similarity) comparison for two ASN1Primitive objects.

encodeConstructedback to summary
pack-priv boolean encodeConstructed()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Doc from org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Return true if this objected is a CONSTRUCTED one, false otherwise.

Returns:boolean

true if CONSTRUCTED bit set on object's tag, false otherwise.

getDEREncodedback to summary
private static byte[] getDEREncoded(ASN1Encodable obj)
getInstanceback to summary
public static ASN1Set getInstance(Object obj)

return an ASN1Set from the given object.

Parameters
obj:Object

the object we want converted.

Returns:ASN1Set

an ASN1Set instance, or null.

Exceptions
IllegalArgumentException:
if the object cannot be converted.
getInstanceback to summary
public static ASN1Set getInstance(ASN1TaggedObject taggedObject, boolean explicit)

Return an ASN1 set from a tagged object. There is a special case here, if an object appears to have been explicitly tagged on reading but we were expecting it to be implicitly tagged in the normal course of events it indicates that we lost the surrounding set - so we need to add it back (this will happen if the tagged object is a sequence that contains other sequences). If you are dealing with implicitly tagged sets you really should be using this method.

Parameters
taggedObject:ASN1TaggedObject

the tagged object.

explicit:boolean

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

Returns:ASN1Set

an ASN1Set instance.

Exceptions
IllegalArgumentException:
if the tagged object cannot be converted.
getObjectAtback to summary
public ASN1Encodable getObjectAt(int index)

return the object at the set position indicated by index.

Parameters
index:int

the set number (starting at zero) of the object

Returns:ASN1Encodable

the object at the set position indicated by index.

getObjectsback to summary
public Enumeration<E> getObjects()
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.

iteratorback to summary
public Iterator<ASN1Encodable> iterator()

Implements org.bouncycastle.util.Iterable.iterator.

Doc from org.bouncycastle.util.Iterable.iterator.

Returns an iterator over a set of elements of type T.

Returns:Iterator<ASN1Encodable>

an Iterator.

lessThanOrEqualback to summary
private static boolean lessThanOrEqual(byte[] a, byte[] b)

return true if a <= b (arrays are assumed padded with zeros).

parserback to summary
public ASN1SetParser parser()
sizeback to summary
public int size()

return the number of objects in this set.

Returns:int

the number of objects in this set.

sortback to summary
private static void sort(ASN1Encodable[] t)
toArrayback to summary
public ASN1Encodable[] toArray()
toDERObjectback to summary
pack-priv ASN1Primitive toDERObject()

Overrides org.bouncycastle.asn1.ASN1Primitive.toDERObject.

Change current SET object to be encoded as DERSet. This is part of Distinguished Encoding Rules form serialization.

Returns:ASN1Primitive

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

a DER version of this.

toDLObjectback to summary
pack-priv ASN1Primitive toDLObject()

Overrides org.bouncycastle.asn1.ASN1Primitive.toDLObject.

Change current SET object to be encoded as DLSet. This is part of Direct Length form serialization.

Returns:ASN1Primitive

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

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.