KeyUsage.fromAsn1 constructor

KeyUsage.fromAsn1(
  1. ASN1BitString bitString
)

Creates a key usage extension from an ASN1BitString.

The ASN.1 definition is:

KeyUsage ::= BIT STRING { digitalSignature (0), nonRepudiation (1), -- recent editions of X.509 have -- renamed this bit to contentCommitment keyEncipherment (2), dataEncipherment (3), keyAgreement (4), keyCertSign (5), cRLSign (6), encipherOnly (7), decipherOnly (8) }

Implementation

factory KeyUsage.fromAsn1(ASN1BitString bitString) {
  var bits = bitString.stringValue
      .map((v) => (v + 256).toRadixString(2).substring(1))
      .join()
      .split('')
      .map((v) => v == '1')
      .toList();
  bits = bits.take(bits.length - bitString.unusedbits).toList();
  bits.addAll(Iterable.generate(9, (_) => false));
  bits = bits.take(9).toList();
  return KeyUsage(
      digitalSignature: bits[0],
      nonRepudiation: bits[1],
      keyEncipherment: bits[2],
      dataEncipherment: bits[3],
      keyAgreement: bits[4],
      keyCertSign: bits[5],
      cRLSign: bits[6],
      encipherOnly: bits[7],
      decipherOnly: bits[8]);
}