Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class Asn1

  1. Object
  2. Asn1

The DER this package reads and writes: a reader over definite-length encodings and the handful of writers the formats here need.

BER’s indefinite lengths are refused. X.509, PKCS#10 and the PKCS#12 files OpenSSL and the JDK write are DER; a file that is not is reported as such rather than half read.

It is public for formats this package does not cover – a CMS SignedData structure, an Apple receipt, an attestation extension – so they are read with the same bounds checks rather than by hand.

Asn1.Reader outer = new Asn1.Reader(der).open(Asn1.SEQUENCE);
String type = outer.oid();
byte[] content = outer.open(Asn1.explicit(0)).raw(Asn1.SEQUENCE);

Nested types

class Asn1.ReaderReads one level of a DER structure.

Fields

public static final int BOOLEAN = 1
public static final int INTEGER = 2
public static final int BIT_STRING = 3
public static final int OCTET_STRING = 4
public static final int NULL = 5
public static final int OID = 6
public static final int UTF8_STRING = 12
public static final int PRINTABLE_STRING = 19
public static final int T61_STRING = 20
public static final int IA5_STRING = 22
public static final int UTC_TIME = 23
public static final int GENERALIZED_TIME = 24
public static final int UNIVERSAL_STRING = 28
public static final int BMP_STRING = 30
public static final int SEQUENCE = 48
public static final int SET = 49

Methods

public static int explicit(int n)The context-specific constructed tag [n].
public static int implicit(int n)The context-specific primitive tag [n].
public static byte[] tlv(int tag, byte[]... parts)
public static byte[] sequence(byte[]... parts)
public static byte[] set(byte[]... parts)
public static byte[] octets(byte[] value)
public static byte[] bitString(byte[] value)
public static byte[] nullValue()
public static byte[] integer(long value)A non-negative INTEGER.
public static byte[] unsignedInteger(byte[] magnitude)An INTEGER from an unsigned magnitude.
public static byte[] oid(String dotted)
public static byte[] utf8String(String value)
public static byte[] ia5String(String value)
public static byte[] printableString(String value)
public static String oidString(byte[] value) throws IOException

Inherited methods

Field details

BOOLEAN

public static final int BOOLEAN = 1

INTEGER

public static final int INTEGER = 2

BIT_STRING

public static final int BIT_STRING = 3

OCTET_STRING

public static final int OCTET_STRING = 4

NULL

public static final int NULL = 5

OID

public static final int OID = 6

UTF8_STRING

public static final int UTF8_STRING = 12

PRINTABLE_STRING

public static final int PRINTABLE_STRING = 19

T61_STRING

public static final int T61_STRING = 20

IA5_STRING

public static final int IA5_STRING = 22

UTC_TIME

public static final int UTC_TIME = 23

GENERALIZED_TIME

public static final int GENERALIZED_TIME = 24

UNIVERSAL_STRING

public static final int UNIVERSAL_STRING = 28

BMP_STRING

public static final int BMP_STRING = 30

SEQUENCE

public static final int SEQUENCE = 48

SET

public static final int SET = 49

Method details

explicit

public static int explicit(int n)
The context-specific constructed tag [n].

implicit

public static int implicit(int n)
The context-specific primitive tag [n].

tlv

public static byte[] tlv(int tag, byte[]... parts)

sequence

public static byte[] sequence(byte[]... parts)

set

public static byte[] set(byte[]... parts)

octets

public static byte[] octets(byte[] value)

bitString

public static byte[] bitString(byte[] value)

nullValue

public static byte[] nullValue()

integer

public static byte[] integer(long value)
A non-negative INTEGER.

unsignedInteger

public static byte[] unsignedInteger(byte[] magnitude)
An INTEGER from an unsigned magnitude.

oid

public static byte[] oid(String dotted)

utf8String

public static byte[] utf8String(String value)

ia5String

public static byte[] ia5String(String value)

printableString

public static byte[] printableString(String value)

oidString

public static String oidString(byte[] value) throws IOException