wrapDER static method

Uint8List wrapDER(
  1. Uint8List payload,
  2. Uint8List oid
)

Implementation

static Uint8List wrapDER(Uint8List payload, Uint8List oid) {
  // The Bit String header needs to include the unused bit count byte in its length
  final bitStringHeaderLength = 2 + encodeLenBytes(payload.length + 1);
  final len = oid.length + bitStringHeaderLength + payload.length;
  int offset = 0;
  final int bufLength = 1 + encodeLenBytes(len) + len;
  final buf = Uint8List(bufLength);
  // Sequence
  buf[offset++] = 0x30;
  // Sequence Length
  offset += encodeLen(buf, offset, len);

  // OID
  buf.setAll(offset, oid);
  offset += oid.length;

  // Bit String Header
  buf[offset++] = 0x03;
  offset += encodeLen(buf, offset, payload.length + 1);
  // 0 padding
  buf[offset++] = 0x00;
  buf.setRange(offset, offset + payload.length, payload);

  return buf;
}