usableForOperation method

bool usableForOperation(
  1. String operation
)

Returns true if this key can be used for the operation

The value of operation should be one of the possible values for keyOperations.

Implementation

bool usableForOperation(String operation) {
  var ops = keyOperations;
  if (ops != null && !ops.contains(operation)) return false;
  var alg = algorithm == null ? null : JsonWebAlgorithm.getByName(algorithm);
  if (alg != null && publicKeyUse != null && alg.use != publicKeyUse) {
    return false;
  }

  switch (operation) {
    case 'sign':
    case 'unwrapKey':
    case 'decrypt':
      return _keyPair.privateKey != null;
    case 'verify':
    case 'wrapKey':
    case 'encrypt':
      return _keyPair.publicKey != null;
  }
  return false;
}