fromAlgorithm static method

dynamic fromAlgorithm(
  1. CryptoAlgorithm algorithm,
  2. dynamic input
)

Creates a cipher/signature instance from a generic algorithm type.

This is a convenience method that dispatches to the appropriate factory method based on the algorithm enum value.

Note: For asymmetric operations, ensure you pass the correct Input type that matches your algorithm.

Implementation

static dynamic fromAlgorithm(
  CryptoAlgorithm algorithm,
  dynamic input,
) {
  if (SymmetricCipherAlgorithmEnum.values.contains(algorithm)) {
    return symmetric(algorithm, input as InputSymmetricCipher);
  } else if (AsymmetricCipherAlgorithmEnum.values.contains(algorithm)) {
    return asymmetric(algorithm, input as InputAsymmetricCipher);
  } else if (SymmetricSignAlgorithmEnum.values.contains(algorithm)) {
    return symmetricSign(algorithm, input as InputSymmetricSign);
  } else if (AsymmetricSignAlgorithmEnum.values.contains(algorithm)) {
    return asymmetricSign(algorithm, input as InputAsymmetricSign);
  } else {
    throw ArgumentError('Unsupported algorithm type: $algorithm');
  }
}