deserialize method

  1. @override
EncodingParams deserialize(
  1. String encoded
)
override

Implementation

@override
EncodingParams deserialize(String encoded) {
  final Uint8List bytes = base64Decode(_padEncodeIfNeeded(encoded));
  final int type = bytes[0];

  int index = TYPE_LENGTH;
  Uint8List? senderPublicKey;
  if (type == EncodeOptions.TYPE_1) {
    senderPublicKey = bytes.sublist(
      index,
      index + KEY_LENGTH,
    );
    index += KEY_LENGTH;
  }
  if (type == EncodeOptions.TYPE_2) {
    senderPublicKey = bytes.sublist(
      index,
      index + KEY_LENGTH,
    );
    // index += KEY_LENGTH;

    Uint8List sealed = bytes.sublist(index);
    // iv is not used in TYPE_2 envelopes
    Uint8List iv = Uint8List(IV_LENGTH)
      ..setAll(0, List.generate(IV_LENGTH, (_) => Random().nextInt(256)));
    Uint8List ivSealed = bytes.sublist(index);

    return EncodingParams(
      type,
      sealed,
      iv,
      ivSealed,
      senderPublicKey: senderPublicKey,
    );
  }

  Uint8List iv = bytes.sublist(index, index + IV_LENGTH);
  Uint8List ivSealed = bytes.sublist(index);
  index += IV_LENGTH;
  Uint8List sealed = bytes.sublist(index);

  return EncodingParams(
    type,
    sealed,
    iv,
    ivSealed,
    senderPublicKey: senderPublicKey,
  );
}