decodePoint method

  1. @override
ECPointBase? decodePoint(
  1. List<int> encoded
)
override

Decode a point on this curve from its ASN.1 encoding. The different encodings are taken account of, including point compression for Fp (X9.62 s 4.2.1 pg 17). @return The decoded point.

Implementation

@override
ECPointBase? decodePoint(List<int> encoded) {
  ECPointBase? p;
  var expectedLength = (fieldSize + 7) ~/ 8;

  switch (encoded[0]) {
    case 0x00: // infinity
      if (encoded.length != 1) {
        throw ArgumentError('Incorrect length for infinity encoding');
      }

      p = infinity;
      break;

    case 0x02: // compressed
    case 0x03: // compressed
      if (encoded.length != (expectedLength + 1)) {
        throw ArgumentError('Incorrect length for compressed encoding');
      }

      var yTilde = encoded[0] & 1;
      var x1 = _fromArray(encoded, 1, expectedLength);

      p = decompressPoint(yTilde, x1);
      break;

    case 0x04: // uncompressed
    case 0x06: // hybrid
    case 0x07: // hybrid
      if (encoded.length != (2 * expectedLength + 1)) {
        throw ArgumentError(
            'Incorrect length for uncompressed/hybrid encoding');
      }

      var x1 = _fromArray(encoded, 1, expectedLength);
      var y1 = _fromArray(encoded, 1 + expectedLength, expectedLength);

      p = createPoint(x1, y1, false);
      break;

    default:
      throw ArgumentError(
          'Invalid point encoding 0x${encoded[0].toRadixString(16)}');
  }

  return p;
}