DerivationArtefacts.fromSerialized constructor Null safety

DerivationArtefacts.fromSerialized(
  1. String serialized
)

Serialize the artefacts in Cryppo's artefact serialization format (serialize) to be appended onto a serialized encrypted string

Implementation

DerivationArtefacts.fromSerialized(String serialized) {
  final parts = serialized.split('.');
  strategy = derivationStrategyFromString(parts[0]);
  final artefacts = parts[1];
  final bsonData = base64Url.decode(artefacts);
  version = utf8.decode(bsonData.sublist(0, 1));
  final bsonBuffer = bsonData.sublist(1);
  final deserialized = BSON().deserialize(BsonBinary.from(bsonBuffer));
  final BsonBinary iv = deserialized['iv'];

  this.iterations = deserialized['i'];
  this.salt = iv.byteList;
  this.length = deserialized['l'];
}