gossamer/subtle_crypto

Types

pub type CryptoKeyPair {
  CryptoKeyPair(
    public_key: crypto_key.CryptoKey,
    private_key: crypto_key.CryptoKey,
  )
}

Constructors

Values

pub fn decrypt(
  algorithm algorithm: encrypt_algorithm.EncryptAlgorithm,
  key key: crypto_key.CryptoKey,
  data data: uint8_array.Uint8Array,
) -> promise.Promise(
  Result(array_buffer.ArrayBuffer, js_error.JsError),
)

Decrypts data with key using algorithm. Returns an error if the key’s usage doesn’t include "decrypt", the key’s algorithm doesn’t match, or data is not valid ciphertext.

pub fn derive_bits(
  algorithm algorithm: derive_algorithm.DeriveAlgorithm,
  base_key key: crypto_key.CryptoKey,
  length length: Int,
) -> promise.Promise(
  Result(array_buffer.ArrayBuffer, js_error.JsError),
)

Derives bits of shared secret from a base key. Returns an error if the key’s usage doesn’t include "deriveBits" or the algorithm is unsupported.

pub fn derive_key(
  algorithm algorithm: derive_algorithm.DeriveAlgorithm,
  base_key key: crypto_key.CryptoKey,
  derived_key_type type_: derived_key_type.DerivedKeyType,
  extractable extractable: Bool,
  usages usages: List(key_usage.KeyUsage),
) -> promise.Promise(
  Result(crypto_key.CryptoKey, js_error.JsError),
)

Derives a new CryptoKey from a base key. Returns an error if the key’s usage doesn’t include "deriveKey" or the algorithm is unsupported.

pub fn digest(
  algorithm algorithm: hash_algorithm.HashAlgorithm,
  data data: uint8_array.Uint8Array,
) -> promise.Promise(
  Result(array_buffer.ArrayBuffer, js_error.JsError),
)

Computes a cryptographic hash of data. Returns an error if the algorithm is not supported or data cannot be processed.

pub fn encrypt(
  algorithm algorithm: encrypt_algorithm.EncryptAlgorithm,
  key key: crypto_key.CryptoKey,
  data data: uint8_array.Uint8Array,
) -> promise.Promise(
  Result(array_buffer.ArrayBuffer, js_error.JsError),
)

Encrypts data with key using algorithm. Returns an error if the key’s usage doesn’t include "encrypt", the key’s algorithm doesn’t match, or the data is invalid for the algorithm.

pub fn export_key(
  format format: key_format.KeyFormat,
  key key: crypto_key.CryptoKey,
) -> promise.Promise(
  Result(array_buffer.ArrayBuffer, js_error.JsError),
)

Exports key in the given format. Returns an error if the key is not extractable.

pub fn export_key_jwk(
  key: crypto_key.CryptoKey,
) -> promise.Promise(
  Result(json_web_key.JsonWebKey, js_error.JsError),
)

Exports key as a JSON Web Key. Returns an error if the key is not extractable.

pub fn generate_key(
  algorithm algorithm: key_gen_algorithm.KeyGenAlgorithm,
  extractable extractable: Bool,
  usages usages: List(key_usage.KeyUsage),
) -> promise.Promise(
  Result(crypto_key.CryptoKey, js_error.JsError),
)

Generates a new symmetric CryptoKey. Returns an error if the algorithm is unsupported or usages is empty.

pub fn generate_key_pair(
  algorithm algorithm: key_pair_gen_algorithm.KeyPairGenAlgorithm,
  extractable extractable: Bool,
  usages usages: List(key_usage.KeyUsage),
) -> promise.Promise(Result(CryptoKeyPair, js_error.JsError))

Generates a new public/private key pair. Returns an error if the algorithm is unsupported or usages is empty.

pub fn import_key(
  format format: key_format.KeyFormat,
  key_data data: uint8_array.Uint8Array,
  algorithm algorithm: import_algorithm.ImportAlgorithm,
  extractable extractable: Bool,
  usages usages: List(key_usage.KeyUsage),
) -> promise.Promise(
  Result(crypto_key.CryptoKey, js_error.JsError),
)

Imports a raw key from data. Returns an error if data doesn’t match format or the algorithm is unsupported.

pub fn import_key_jwk(
  key_data data: json_web_key.JsonWebKey,
  algorithm algorithm: import_algorithm.ImportAlgorithm,
  extractable extractable: Bool,
  usages usages: List(key_usage.KeyUsage),
) -> promise.Promise(
  Result(crypto_key.CryptoKey, js_error.JsError),
)

Imports a key from a JSON Web Key. Returns an error if data is malformed or the algorithm is unsupported.

pub fn sign(
  algorithm algorithm: sign_algorithm.SignAlgorithm,
  key key: crypto_key.CryptoKey,
  data data: uint8_array.Uint8Array,
) -> promise.Promise(
  Result(array_buffer.ArrayBuffer, js_error.JsError),
)

Produces a digital signature of data with key. Returns an error if the key’s usage doesn’t include "sign" or the key’s algorithm doesn’t match.

pub fn unwrap_key(
  format format: key_format.KeyFormat,
  wrapped_key wrapped_key: uint8_array.Uint8Array,
  unwrapping_key unwrapping_key: crypto_key.CryptoKey,
  unwrap_algorithm unwrap_algorithm: wrap_algorithm.WrapAlgorithm,
  unwrapped_key_algorithm unwrapped_key_algorithm: import_algorithm.ImportAlgorithm,
  extractable extractable: Bool,
  usages usages: List(key_usage.KeyUsage),
) -> promise.Promise(
  Result(crypto_key.CryptoKey, js_error.JsError),
)

Decrypts wrapped_key with unwrapping_key and imports the result. Returns an error if the unwrapping fails or the imported key is invalid for the specified algorithm.

pub fn unwrap_key_jwk(
  wrapped_key wrapped_key: uint8_array.Uint8Array,
  unwrapping_key unwrapping_key: crypto_key.CryptoKey,
  unwrap_algorithm unwrap_algorithm: wrap_algorithm.WrapAlgorithm,
  unwrapped_key_algorithm unwrapped_key_algorithm: import_algorithm.ImportAlgorithm,
  extractable extractable: Bool,
  usages usages: List(key_usage.KeyUsage),
) -> promise.Promise(
  Result(crypto_key.CryptoKey, js_error.JsError),
)

Like unwrap_key, but imports the decrypted key as a JSON Web Key.

pub fn verify(
  algorithm algorithm: sign_algorithm.SignAlgorithm,
  key key: crypto_key.CryptoKey,
  signature signature: uint8_array.Uint8Array,
  data data: uint8_array.Uint8Array,
) -> promise.Promise(Result(Bool, js_error.JsError))

Verifies signature against data using key. Returns an error if the key’s usage doesn’t include "verify" or the key’s algorithm doesn’t match.

pub fn wrap_key(
  format format: key_format.KeyFormat,
  key key: crypto_key.CryptoKey,
  wrapping_key wrapping_key: crypto_key.CryptoKey,
  algorithm algorithm: wrap_algorithm.WrapAlgorithm,
) -> promise.Promise(
  Result(array_buffer.ArrayBuffer, js_error.JsError),
)

Exports key in raw form and encrypts it with wrapping_key. Returns an error if either key’s usage doesn’t allow the operation or the wrapping key’s algorithm is unsupported.

pub fn wrap_key_jwk(
  key key: crypto_key.CryptoKey,
  wrapping_key wrapping_key: crypto_key.CryptoKey,
  algorithm algorithm: wrap_algorithm.WrapAlgorithm,
) -> promise.Promise(
  Result(array_buffer.ArrayBuffer, js_error.JsError),
)

Like wrap_key, but exports key as a JSON Web Key before wrapping.

Search Document