decodePoint static method

ECPublicKey decodePoint(
  1. Uint8List bytes,
  2. int offset
)

Implementation

static ECPublicKey decodePoint(Uint8List bytes, int offset) {
  if (bytes.length - offset < 1) {
    throw InvalidKeyException('No key type identifier');
  }

  final type = bytes[offset] & 0xFF;

  switch (type) {
    case Curve.djbType:
      if (bytes.length - offset < 33) {
        throw InvalidKeyException('Bad key length: ${bytes.length}');
      }

      final keyBytes = Uint8List(32);
      arraycopy(bytes, offset + 1, keyBytes, 0, keyBytes.length);
      return DjbECPublicKey(keyBytes);
    default:
      throw InvalidKeyException('Bad key type: $type');
  }
}