StatelessFileSharingEncryptedSource.fromXml constructor

StatelessFileSharingEncryptedSource.fromXml(
  1. XMLNode element
)

Implementation

factory StatelessFileSharingEncryptedSource.fromXml(XMLNode element) {
  assert(
    element.attributes['xmlns'] == sfsEncryptionXmlns,
    'Element has invalid xmlns',
  );

  final key = base64Decode(element.firstTag('key')!.text!);
  final iv = base64Decode(element.firstTag('iv')!.text!);
  final sources = element.firstTag('sources', xmlns: sfsXmlns)!.children;

  // Find the first URL source
  final source = sources.firstWhereOrNull(
    (XMLNode child) =>
        child.tag == 'url-data' && child.attributes['xmlns'] == urlDataXmlns,
  )!;

  // Find hashes
  final hashes = <HashFunction, String>{};
  for (final hash in element.findTags('hash', xmlns: hashXmlns)) {
    final hashFunction =
        HashFunction.fromName(hash.attributes['algo']! as String);
    hashes[hashFunction] = hash.text!;
  }

  return StatelessFileSharingEncryptedSource(
    SFSEncryptionType.fromNamespace(element.attributes['cipher']! as String),
    key,
    iv,
    hashes,
    StatelessFileSharingUrlSource.fromXml(source),
  );
}