toBytes method

Uint8List toBytes()

Returns the underlying bytes, decoding when necessary.

Implementation

Uint8List toBytes() {
  if (value is Uint8List) {
    return value as Uint8List;
  }
  final stringValue = value as String;
  switch (format) {
    case KeyFormat.base64:
      return Uint8List.fromList(base64Decode(stringValue));
    case KeyFormat.pem:
      return Uint8List.fromList(base64Decode(_stripPem(stringValue)));
    case KeyFormat.hex:
      return Uint8List.fromList(_decodeHex(stringValue));
    case KeyFormat.raw:
      throw StateError('RAW values must be provided as byte data.');
  }
}