#![allow(dead_code, unused_variables)]
use core::fmt;
use core::mem::MaybeUninit;
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct CryptoErrno(u16);
pub const CRYPTO_ERRNO_SUCCESS: CryptoErrno = CryptoErrno(0);
pub const CRYPTO_ERRNO_GUEST_ERROR: CryptoErrno = CryptoErrno(1);
pub const CRYPTO_ERRNO_NOT_IMPLEMENTED: CryptoErrno = CryptoErrno(2);
pub const CRYPTO_ERRNO_UNSUPPORTED_FEATURE: CryptoErrno = CryptoErrno(3);
pub const CRYPTO_ERRNO_PROHIBITED_OPERATION: CryptoErrno = CryptoErrno(4);
pub const CRYPTO_ERRNO_UNSUPPORTED_ENCODING: CryptoErrno = CryptoErrno(5);
pub const CRYPTO_ERRNO_UNSUPPORTED_ALGORITHM: CryptoErrno = CryptoErrno(6);
pub const CRYPTO_ERRNO_UNSUPPORTED_OPTION: CryptoErrno = CryptoErrno(7);
pub const CRYPTO_ERRNO_INVALID_KEY: CryptoErrno = CryptoErrno(8);
pub const CRYPTO_ERRNO_INVALID_LENGTH: CryptoErrno = CryptoErrno(9);
pub const CRYPTO_ERRNO_VERIFICATION_FAILED: CryptoErrno = CryptoErrno(10);
pub const CRYPTO_ERRNO_RNG_ERROR: CryptoErrno = CryptoErrno(11);
pub const CRYPTO_ERRNO_ALGORITHM_FAILURE: CryptoErrno = CryptoErrno(12);
pub const CRYPTO_ERRNO_INVALID_SIGNATURE: CryptoErrno = CryptoErrno(13);
pub const CRYPTO_ERRNO_CLOSED: CryptoErrno = CryptoErrno(14);
pub const CRYPTO_ERRNO_INVALID_HANDLE: CryptoErrno = CryptoErrno(15);
pub const CRYPTO_ERRNO_OVERFLOW: CryptoErrno = CryptoErrno(16);
pub const CRYPTO_ERRNO_INTERNAL_ERROR: CryptoErrno = CryptoErrno(17);
pub const CRYPTO_ERRNO_TOO_MANY_HANDLES: CryptoErrno = CryptoErrno(18);
pub const CRYPTO_ERRNO_KEY_NOT_SUPPORTED: CryptoErrno = CryptoErrno(19);
pub const CRYPTO_ERRNO_KEY_REQUIRED: CryptoErrno = CryptoErrno(20);
pub const CRYPTO_ERRNO_INVALID_TAG: CryptoErrno = CryptoErrno(21);
pub const CRYPTO_ERRNO_INVALID_OPERATION: CryptoErrno = CryptoErrno(22);
pub const CRYPTO_ERRNO_NONCE_REQUIRED: CryptoErrno = CryptoErrno(23);
pub const CRYPTO_ERRNO_INVALID_NONCE: CryptoErrno = CryptoErrno(24);
pub const CRYPTO_ERRNO_OPTION_NOT_SET: CryptoErrno = CryptoErrno(25);
pub const CRYPTO_ERRNO_NOT_FOUND: CryptoErrno = CryptoErrno(26);
pub const CRYPTO_ERRNO_PARAMETERS_MISSING: CryptoErrno = CryptoErrno(27);
pub const CRYPTO_ERRNO_IN_PROGRESS: CryptoErrno = CryptoErrno(28);
pub const CRYPTO_ERRNO_INCOMPATIBLE_KEYS: CryptoErrno = CryptoErrno(29);
pub const CRYPTO_ERRNO_EXPIRED: CryptoErrno = CryptoErrno(30);
impl CryptoErrno {
pub const fn raw(&self) -> u16 {
self.0
}
pub fn name(&self) -> &'static str {
match self.0 {
0 => "SUCCESS",
1 => "GUEST_ERROR",
2 => "NOT_IMPLEMENTED",
3 => "UNSUPPORTED_FEATURE",
4 => "PROHIBITED_OPERATION",
5 => "UNSUPPORTED_ENCODING",
6 => "UNSUPPORTED_ALGORITHM",
7 => "UNSUPPORTED_OPTION",
8 => "INVALID_KEY",
9 => "INVALID_LENGTH",
10 => "VERIFICATION_FAILED",
11 => "RNG_ERROR",
12 => "ALGORITHM_FAILURE",
13 => "INVALID_SIGNATURE",
14 => "CLOSED",
15 => "INVALID_HANDLE",
16 => "OVERFLOW",
17 => "INTERNAL_ERROR",
18 => "TOO_MANY_HANDLES",
19 => "KEY_NOT_SUPPORTED",
20 => "KEY_REQUIRED",
21 => "INVALID_TAG",
22 => "INVALID_OPERATION",
23 => "NONCE_REQUIRED",
24 => "INVALID_NONCE",
25 => "OPTION_NOT_SET",
26 => "NOT_FOUND",
27 => "PARAMETERS_MISSING",
28 => "IN_PROGRESS",
29 => "INCOMPATIBLE_KEYS",
30 => "EXPIRED",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
pub fn message(&self) -> &'static str {
match self.0 {
0 => "Operation succeeded.",
1 => {
"An error occurred when trying to during a conversion from a host type to a guest \
type.
Only an internal bug can throw this error."
}
2 => "The requested operation is valid, but not implemented by the host.",
3 => "The requested feature is not supported by the chosen algorithm.",
4 => "The requested operation is valid, but was administratively prohibited.",
5 => "Unsupported encoding for an import or export operation.",
6 => "The requested algorithm is not supported by the host.",
7 => "The requested option is not supported by the currently selected algorithm.",
8 => {
"An invalid or incompatible key was supplied.
The key may not be valid, or was generated for a different algorithm or parameters set."
}
9 => {
"The currently selected algorithm doesn't support the requested output length.
This error is thrown by non-extensible hash functions, when requesting an output size larger than \
they produce out of a single block."
}
10 => "A signature or authentication tag verification failed.",
11 => {
"A secure random numbers generator is not available.
The requested operation requires random numbers, but the host cannot securely generate them at the \
moment."
}
12 => {
"An error was returned by the underlying cryptography library.
The host may be running out of memory, parameters may be incompatible with the chosen \
implementation of an algorithm or another unexpected error may have happened.
Ideally, the specification should provide enough details and guidance to make this error \
impossible to ever be thrown.
Realistically, the WASI crypto module cannot possibly cover all possible error types \
implementations can return, especially since some of these may be \
language-specific.
This error can thus be thrown when other error types are not suitable, and when the original error \
comes from the cryptographic primitives themselves and not from the WASI module."
}
13 => "The supplied signature is invalid, or incompatible with the chosen algorithm.",
14 => "An attempt was made to close a handle that was already closed.",
15 => {
"A function was called with an unassigned handle, a closed handle, or handle of an \
unexpected type."
}
16 => {
"The host needs to copy data to a guest-allocated buffer, but that buffer is too \
small."
}
17 => {
"An internal error occurred.
This error is reserved to internal consistency checks, and must only be sent if the internal state \
of the host remains safe after an inconsistency was detected."
}
18 => {
"Too many handles are currently open, and a new one cannot be created.
Implementations are free to represent handles as they want, and to enforce limits to limit \
resources usage."
}
19 => {
"A key was provided, but the chosen algorithm doesn't support keys.
This is returned by symmetric operations.
Many hash functions, in particular, do not support keys without being used in particular \
constructions.
Blindly ignoring a key provided by mistake while trying to open a context for such as function \
could cause serious security vulnerabilities.
These functions must refuse to create the context and return this error instead."
}
20 => "A key is required for the chosen algorithm, but none was given.",
21 => {
"The provided authentication tag is invalid or incompatible with the current \
algorithm.
This error is returned by decryption functions and tag verification functions.
Unlike `verification_failed`, this error code is returned when the tag cannot possibly verify for \
any input."
}
22 => {
"The requested operation is incompatible with the current scheme.
For example, the `symmetric_state_encrypt()` function cannot complete if the selected construction \
is a key derivation function.
This error code will be returned instead."
}
23 => {
"A nonce is required.
Most encryption schemes require a nonce.
In the absence of a nonce, the WASI cryptography module can automatically generate one, if that \
can be done safely. The nonce can be retrieved later with the \
`symmetric_state_option_get()` function using the `nonce` parameter.
If automatically generating a nonce cannot be done safely, the module never falls back to an \
insecure option and requests an explicit nonce by throwing that error."
}
24 => "The provided nonce doesn't have a correct size for the given cipher.",
25 => {
"The named option was not set.
The caller tried to read the value of an option that was not set.
This error is used to make the distinction between an empty option, and an option that was not set \
and left to its default value."
}
26 => {
"A key or key pair matching the requested identifier cannot be found using the \
supplied information.
This error is returned by a secrets manager via the `keypair_from_id()` function."
}
27 => {
"The algorithm requires parameters that haven't been set.
Non-generic options are required and must be given by building an `options` set and giving that \
object to functions instantiating that algorithm."
}
28 => {
"A requested computation is not done yet, and additional calls to the function are \
required.
Some functions, such as functions generating key pairs and password stretching functions, can take \
a long time to complete.
In order to avoid a host call to be blocked for too long, these functions can return prematurely, \
requiring additional calls with the same parameters until they complete."
}
29 => {
"Multiple keys have been provided, but they do not share the same type.
This error is returned when trying to build a key pair from a public key and a secret key that \
were created for different and incompatible algorithms."
}
30 => "A managed key or secret expired and cannot be used any more.",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
}
impl fmt::Debug for CryptoErrno {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CryptoErrno")
.field("code", &self.0)
.field("name", &self.name())
.field("message", &self.message())
.finish()
}
}
impl fmt::Display for CryptoErrno {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} (error {})", self.name(), self.0)
}
}
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
impl std::error::Error for CryptoErrno {}
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct KeypairEncoding(u16);
pub const KEYPAIR_ENCODING_RAW: KeypairEncoding = KeypairEncoding(0);
pub const KEYPAIR_ENCODING_PKCS8: KeypairEncoding = KeypairEncoding(1);
pub const KEYPAIR_ENCODING_PEM: KeypairEncoding = KeypairEncoding(2);
pub const KEYPAIR_ENCODING_LOCAL: KeypairEncoding = KeypairEncoding(3);
impl KeypairEncoding {
pub const fn raw(&self) -> u16 {
self.0
}
pub fn name(&self) -> &'static str {
match self.0 {
0 => "RAW",
1 => "PKCS8",
2 => "PEM",
3 => "LOCAL",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
pub fn message(&self) -> &'static str {
match self.0 {
0 => "Raw bytes.",
1 => "PCSK8/DER encoding.",
2 => "PEM encoding.",
3 => "Implementation-defined encoding.",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
}
impl fmt::Debug for KeypairEncoding {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("KeypairEncoding")
.field("code", &self.0)
.field("name", &self.name())
.field("message", &self.message())
.finish()
}
}
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct PublickeyEncoding(u16);
pub const PUBLICKEY_ENCODING_RAW: PublickeyEncoding = PublickeyEncoding(0);
pub const PUBLICKEY_ENCODING_PKCS8: PublickeyEncoding = PublickeyEncoding(1);
pub const PUBLICKEY_ENCODING_PEM: PublickeyEncoding = PublickeyEncoding(2);
pub const PUBLICKEY_ENCODING_SEC: PublickeyEncoding = PublickeyEncoding(3);
pub const PUBLICKEY_ENCODING_LOCAL: PublickeyEncoding = PublickeyEncoding(4);
impl PublickeyEncoding {
pub const fn raw(&self) -> u16 {
self.0
}
pub fn name(&self) -> &'static str {
match self.0 {
0 => "RAW",
1 => "PKCS8",
2 => "PEM",
3 => "SEC",
4 => "LOCAL",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
pub fn message(&self) -> &'static str {
match self.0 {
0 => "Raw bytes.",
1 => "PKCS8/DER encoding.",
2 => "PEM encoding.",
3 => "SEC-1 encoding.",
4 => "Implementation-defined encoding.",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
}
impl fmt::Debug for PublickeyEncoding {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PublickeyEncoding")
.field("code", &self.0)
.field("name", &self.name())
.field("message", &self.message())
.finish()
}
}
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct SecretkeyEncoding(u16);
pub const SECRETKEY_ENCODING_RAW: SecretkeyEncoding = SecretkeyEncoding(0);
pub const SECRETKEY_ENCODING_PKCS8: SecretkeyEncoding = SecretkeyEncoding(1);
pub const SECRETKEY_ENCODING_PEM: SecretkeyEncoding = SecretkeyEncoding(2);
pub const SECRETKEY_ENCODING_SEC: SecretkeyEncoding = SecretkeyEncoding(3);
pub const SECRETKEY_ENCODING_LOCAL: SecretkeyEncoding = SecretkeyEncoding(4);
impl SecretkeyEncoding {
pub const fn raw(&self) -> u16 {
self.0
}
pub fn name(&self) -> &'static str {
match self.0 {
0 => "RAW",
1 => "PKCS8",
2 => "PEM",
3 => "SEC",
4 => "LOCAL",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
pub fn message(&self) -> &'static str {
match self.0 {
0 => "Raw bytes.",
1 => "PKCS8/DER encoding.",
2 => "PEM encoding.",
3 => "SEC-1 encoding.",
4 => "Implementation-defined encoding.",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
}
impl fmt::Debug for SecretkeyEncoding {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SecretkeyEncoding")
.field("code", &self.0)
.field("name", &self.name())
.field("message", &self.message())
.finish()
}
}
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct SignatureEncoding(u16);
pub const SIGNATURE_ENCODING_RAW: SignatureEncoding = SignatureEncoding(0);
pub const SIGNATURE_ENCODING_DER: SignatureEncoding = SignatureEncoding(1);
impl SignatureEncoding {
pub const fn raw(&self) -> u16 {
self.0
}
pub fn name(&self) -> &'static str {
match self.0 {
0 => "RAW",
1 => "DER",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
pub fn message(&self) -> &'static str {
match self.0 {
0 => "Raw bytes.",
1 => "DER encoding.",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
}
impl fmt::Debug for SignatureEncoding {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SignatureEncoding")
.field("code", &self.0)
.field("name", &self.name())
.field("message", &self.message())
.finish()
}
}
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct AlgorithmType(u16);
pub const ALGORITHM_TYPE_SIGNATURES: AlgorithmType = AlgorithmType(0);
pub const ALGORITHM_TYPE_SYMMETRIC: AlgorithmType = AlgorithmType(1);
pub const ALGORITHM_TYPE_KEY_EXCHANGE: AlgorithmType = AlgorithmType(2);
impl AlgorithmType {
pub const fn raw(&self) -> u16 {
self.0
}
pub fn name(&self) -> &'static str {
match self.0 {
0 => "SIGNATURES",
1 => "SYMMETRIC",
2 => "KEY_EXCHANGE",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
pub fn message(&self) -> &'static str {
match self.0 {
0 => "",
1 => "",
2 => "",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
}
impl fmt::Debug for AlgorithmType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("AlgorithmType")
.field("code", &self.0)
.field("name", &self.name())
.field("message", &self.message())
.finish()
}
}
pub type Version = u64;
pub type Size = usize;
pub type Timestamp = u64;
pub type ArrayOutput = u32;
pub type Options = u32;
pub type SecretsManager = u32;
pub type Keypair = u32;
pub type SignatureState = u32;
pub type Signature = u32;
pub type Publickey = u32;
pub type Secretkey = u32;
pub type SignatureVerificationState = u32;
pub type SymmetricState = u32;
pub type SymmetricKey = u32;
pub type SymmetricTag = u32;
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct OptOptionsU(u8);
pub const OPT_OPTIONS_U_SOME: OptOptionsU = OptOptionsU(0);
pub const OPT_OPTIONS_U_NONE: OptOptionsU = OptOptionsU(1);
impl OptOptionsU {
pub const fn raw(&self) -> u8 {
self.0
}
pub fn name(&self) -> &'static str {
match self.0 {
0 => "SOME",
1 => "NONE",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
pub fn message(&self) -> &'static str {
match self.0 {
0 => "",
1 => "",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
}
impl fmt::Debug for OptOptionsU {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OptOptionsU")
.field("code", &self.0)
.field("name", &self.name())
.field("message", &self.message())
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union OptOptionsUnion {
pub none: (),
pub some: Options,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct OptOptions {
pub tag: u8,
pub u: OptOptionsUnion,
}
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct OptSymmetricKeyU(u8);
pub const OPT_SYMMETRIC_KEY_U_SOME: OptSymmetricKeyU = OptSymmetricKeyU(0);
pub const OPT_SYMMETRIC_KEY_U_NONE: OptSymmetricKeyU = OptSymmetricKeyU(1);
impl OptSymmetricKeyU {
pub const fn raw(&self) -> u8 {
self.0
}
pub fn name(&self) -> &'static str {
match self.0 {
0 => "SOME",
1 => "NONE",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
pub fn message(&self) -> &'static str {
match self.0 {
0 => "",
1 => "",
_ => unsafe { core::hint::unreachable_unchecked() },
}
}
}
impl fmt::Debug for OptSymmetricKeyU {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OptSymmetricKeyU")
.field("code", &self.0)
.field("name", &self.name())
.field("message", &self.message())
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union OptSymmetricKeyUnion {
pub none: (),
pub some: SymmetricKey,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct OptSymmetricKey {
pub tag: u8,
pub u: OptSymmetricKeyUnion,
}
pub type U64 = u64;
pub type SignatureKeypair = Keypair;
pub type SignaturePublickey = Publickey;
pub type SignatureSecretkey = Secretkey;
pub type KxKeypair = Keypair;
pub type KxPublickey = Publickey;
pub type KxSecretkey = Secretkey;
pub unsafe fn options_open(algorithm_type: AlgorithmType) -> Result<Options, CryptoErrno> {
let mut rp0 = MaybeUninit::<Options>::uninit();
let ret = wasi_ephemeral_crypto_common::options_open(
algorithm_type.0 as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Options)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn options_close(handle: Options) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_common::options_close(handle as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn options_set(
handle: Options,
name: &str,
value: *const u8,
value_len: Size,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_common::options_set(
handle as i32,
name.as_ptr() as i32,
name.len() as i32,
value as i32,
value_len as i32,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn options_set_u64(handle: Options, name: &str, value: u64) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_common::options_set_u64(
handle as i32,
name.as_ptr() as i32,
name.len() as i32,
value as i64,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn options_set_guest_buffer(
handle: Options,
name: &str,
buffer: *mut u8,
buffer_len: Size,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_common::options_set_guest_buffer(
handle as i32,
name.as_ptr() as i32,
name.len() as i32,
buffer as i32,
buffer_len as i32,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn array_output_len(array_output: ArrayOutput) -> Result<Size, CryptoErrno> {
let mut rp0 = MaybeUninit::<Size>::uninit();
let ret = wasi_ephemeral_crypto_common::array_output_len(
array_output as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn array_output_pull(
array_output: ArrayOutput,
buf: *mut u8,
buf_len: Size,
) -> Result<Size, CryptoErrno> {
let mut rp0 = MaybeUninit::<Size>::uninit();
let ret = wasi_ephemeral_crypto_common::array_output_pull(
array_output as i32,
buf as i32,
buf_len as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn secrets_manager_open(options: OptOptions) -> Result<SecretsManager, CryptoErrno> {
let mut rp0 = MaybeUninit::<SecretsManager>::uninit();
let ret = wasi_ephemeral_crypto_common::secrets_manager_open(
&options as *const _ as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SecretsManager
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn secrets_manager_close(secrets_manager: SecretsManager) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_common::secrets_manager_close(secrets_manager as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn secrets_manager_invalidate(
secrets_manager: SecretsManager,
key_id: *const u8,
key_id_len: Size,
key_version: Version,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_common::secrets_manager_invalidate(
secrets_manager as i32,
key_id as i32,
key_id_len as i32,
key_version as i64,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub mod wasi_ephemeral_crypto_common {
#[link(wasm_import_module = "wasi_ephemeral_crypto_common")]
extern "C" {
pub fn options_open(arg0: i32, arg1: i32) -> i32;
pub fn options_close(arg0: i32) -> i32;
pub fn options_set(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32) -> i32;
pub fn options_set_u64(arg0: i32, arg1: i32, arg2: i32, arg3: i64) -> i32;
pub fn options_set_guest_buffer(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
) -> i32;
pub fn array_output_len(arg0: i32, arg1: i32) -> i32;
pub fn array_output_pull(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
pub fn secrets_manager_open(arg0: i32, arg1: i32) -> i32;
pub fn secrets_manager_close(arg0: i32) -> i32;
pub fn secrets_manager_invalidate(arg0: i32, arg1: i32, arg2: i32, arg3: i64) -> i32;
}
}
pub unsafe fn keypair_generate(
algorithm_type: AlgorithmType,
algorithm: &str,
options: OptOptions,
) -> Result<Keypair, CryptoErrno> {
let mut rp0 = MaybeUninit::<Keypair>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_generate(
algorithm_type.0 as i32,
algorithm.as_ptr() as i32,
algorithm.len() as i32,
&options as *const _ as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Keypair)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn keypair_import(
algorithm_type: AlgorithmType,
algorithm: &str,
encoded: *const u8,
encoded_len: Size,
encoding: KeypairEncoding,
) -> Result<Keypair, CryptoErrno> {
let mut rp0 = MaybeUninit::<Keypair>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_import(
algorithm_type.0 as i32,
algorithm.as_ptr() as i32,
algorithm.len() as i32,
encoded as i32,
encoded_len as i32,
encoding.0 as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Keypair)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn keypair_generate_managed(
secrets_manager: SecretsManager,
algorithm_type: AlgorithmType,
algorithm: &str,
options: OptOptions,
) -> Result<Keypair, CryptoErrno> {
let mut rp0 = MaybeUninit::<Keypair>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_generate_managed(
secrets_manager as i32,
algorithm_type.0 as i32,
algorithm.as_ptr() as i32,
algorithm.len() as i32,
&options as *const _ as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Keypair)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn keypair_store_managed(
secrets_manager: SecretsManager,
kp: Keypair,
kp_id: *mut u8,
kp_id_max_len: Size,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_store_managed(
secrets_manager as i32,
kp as i32,
kp_id as i32,
kp_id_max_len as i32,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn keypair_replace_managed(
secrets_manager: SecretsManager,
kp_old: Keypair,
kp_new: Keypair,
) -> Result<Version, CryptoErrno> {
let mut rp0 = MaybeUninit::<Version>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_replace_managed(
secrets_manager as i32,
kp_old as i32,
kp_new as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Version)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn keypair_id(
kp: Keypair,
kp_id: *mut u8,
kp_id_max_len: Size,
) -> Result<(Size, Version), CryptoErrno> {
let mut rp0 = MaybeUninit::<Size>::uninit();
let mut rp1 = MaybeUninit::<Version>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_id(
kp as i32,
kp_id as i32,
kp_id_max_len as i32,
rp0.as_mut_ptr() as i32,
rp1.as_mut_ptr() as i32,
);
match ret {
0 => Ok((
core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size),
core::ptr::read(rp1.as_mut_ptr() as i32 as *const Version),
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn keypair_from_id(
secrets_manager: SecretsManager,
kp_id: *const u8,
kp_id_len: Size,
kp_version: Version,
) -> Result<Keypair, CryptoErrno> {
let mut rp0 = MaybeUninit::<Keypair>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_from_id(
secrets_manager as i32,
kp_id as i32,
kp_id_len as i32,
kp_version as i64,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Keypair)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn keypair_from_pk_and_sk(
publickey: Publickey,
secretkey: Secretkey,
) -> Result<Keypair, CryptoErrno> {
let mut rp0 = MaybeUninit::<Keypair>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_from_pk_and_sk(
publickey as i32,
secretkey as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Keypair)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn keypair_export(
kp: Keypair,
encoding: KeypairEncoding,
) -> Result<ArrayOutput, CryptoErrno> {
let mut rp0 = MaybeUninit::<ArrayOutput>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_export(
kp as i32,
encoding.0 as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const ArrayOutput
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn keypair_publickey(kp: Keypair) -> Result<Publickey, CryptoErrno> {
let mut rp0 = MaybeUninit::<Publickey>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_publickey(
kp as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Publickey)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn keypair_secretkey(kp: Keypair) -> Result<Secretkey, CryptoErrno> {
let mut rp0 = MaybeUninit::<Secretkey>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_secretkey(
kp as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Secretkey)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn keypair_close(kp: Keypair) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_asymmetric_common::keypair_close(kp as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn publickey_import(
algorithm_type: AlgorithmType,
algorithm: &str,
encoded: *const u8,
encoded_len: Size,
encoding: PublickeyEncoding,
) -> Result<Publickey, CryptoErrno> {
let mut rp0 = MaybeUninit::<Publickey>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::publickey_import(
algorithm_type.0 as i32,
algorithm.as_ptr() as i32,
algorithm.len() as i32,
encoded as i32,
encoded_len as i32,
encoding.0 as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Publickey)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn publickey_export(
pk: Publickey,
encoding: PublickeyEncoding,
) -> Result<ArrayOutput, CryptoErrno> {
let mut rp0 = MaybeUninit::<ArrayOutput>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::publickey_export(
pk as i32,
encoding.0 as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const ArrayOutput
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn publickey_verify(pk: Publickey) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_asymmetric_common::publickey_verify(pk as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn publickey_from_secretkey(sk: Secretkey) -> Result<Publickey, CryptoErrno> {
let mut rp0 = MaybeUninit::<Publickey>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::publickey_from_secretkey(
sk as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Publickey)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn publickey_close(pk: Publickey) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_asymmetric_common::publickey_close(pk as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn secretkey_import(
algorithm_type: AlgorithmType,
algorithm: &str,
encoded: *const u8,
encoded_len: Size,
encoding: SecretkeyEncoding,
) -> Result<Secretkey, CryptoErrno> {
let mut rp0 = MaybeUninit::<Secretkey>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::secretkey_import(
algorithm_type.0 as i32,
algorithm.as_ptr() as i32,
algorithm.len() as i32,
encoded as i32,
encoded_len as i32,
encoding.0 as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Secretkey)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn secretkey_export(
sk: Secretkey,
encoding: SecretkeyEncoding,
) -> Result<ArrayOutput, CryptoErrno> {
let mut rp0 = MaybeUninit::<ArrayOutput>::uninit();
let ret = wasi_ephemeral_crypto_asymmetric_common::secretkey_export(
sk as i32,
encoding.0 as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const ArrayOutput
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn secretkey_close(sk: Secretkey) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_asymmetric_common::secretkey_close(sk as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub mod wasi_ephemeral_crypto_asymmetric_common {
#[link(wasm_import_module = "wasi_ephemeral_crypto_asymmetric_common")]
extern "C" {
pub fn keypair_generate(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32) -> i32;
pub fn keypair_import(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
arg5: i32,
arg6: i32,
) -> i32;
pub fn keypair_generate_managed(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
arg5: i32,
) -> i32;
pub fn keypair_store_managed(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
pub fn keypair_replace_managed(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
pub fn keypair_id(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32) -> i32;
pub fn keypair_from_id(arg0: i32, arg1: i32, arg2: i32, arg3: i64, arg4: i32) -> i32;
pub fn keypair_from_pk_and_sk(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn keypair_export(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn keypair_publickey(arg0: i32, arg1: i32) -> i32;
pub fn keypair_secretkey(arg0: i32, arg1: i32) -> i32;
pub fn keypair_close(arg0: i32) -> i32;
pub fn publickey_import(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
arg5: i32,
arg6: i32,
) -> i32;
pub fn publickey_export(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn publickey_verify(arg0: i32) -> i32;
pub fn publickey_from_secretkey(arg0: i32, arg1: i32) -> i32;
pub fn publickey_close(arg0: i32) -> i32;
pub fn secretkey_import(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
arg5: i32,
arg6: i32,
) -> i32;
pub fn secretkey_export(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn secretkey_close(arg0: i32) -> i32;
}
}
pub unsafe fn signature_export(
signature: Signature,
encoding: SignatureEncoding,
) -> Result<ArrayOutput, CryptoErrno> {
let mut rp0 = MaybeUninit::<ArrayOutput>::uninit();
let ret = wasi_ephemeral_crypto_signatures::signature_export(
signature as i32,
encoding.0 as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const ArrayOutput
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn signature_import(
algorithm: &str,
encoded: *const u8,
encoded_len: Size,
encoding: SignatureEncoding,
) -> Result<Signature, CryptoErrno> {
let mut rp0 = MaybeUninit::<Signature>::uninit();
let ret = wasi_ephemeral_crypto_signatures::signature_import(
algorithm.as_ptr() as i32,
algorithm.len() as i32,
encoded as i32,
encoded_len as i32,
encoding.0 as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Signature)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn signature_state_open(kp: SignatureKeypair) -> Result<SignatureState, CryptoErrno> {
let mut rp0 = MaybeUninit::<SignatureState>::uninit();
let ret =
wasi_ephemeral_crypto_signatures::signature_state_open(kp as i32, rp0.as_mut_ptr() as i32);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SignatureState
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn signature_state_update(
state: SignatureState,
input: *const u8,
input_len: Size,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_signatures::signature_state_update(
state as i32,
input as i32,
input_len as i32,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn signature_state_sign(state: SignatureState) -> Result<ArrayOutput, CryptoErrno> {
let mut rp0 = MaybeUninit::<ArrayOutput>::uninit();
let ret = wasi_ephemeral_crypto_signatures::signature_state_sign(
state as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const ArrayOutput
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn signature_state_close(state: SignatureState) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_signatures::signature_state_close(state as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn signature_verification_state_open(
kp: SignaturePublickey,
) -> Result<SignatureVerificationState, CryptoErrno> {
let mut rp0 = MaybeUninit::<SignatureVerificationState>::uninit();
let ret = wasi_ephemeral_crypto_signatures::signature_verification_state_open(
kp as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SignatureVerificationState
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn signature_verification_state_update(
state: SignatureVerificationState,
input: *const u8,
input_len: Size,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_signatures::signature_verification_state_update(
state as i32,
input as i32,
input_len as i32,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn signature_verification_state_verify(
state: SignatureVerificationState,
signature: Signature,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_signatures::signature_verification_state_verify(
state as i32,
signature as i32,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn signature_verification_state_close(
state: SignatureVerificationState,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_signatures::signature_verification_state_close(state as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn signature_close(signature: Signature) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_signatures::signature_close(signature as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub mod wasi_ephemeral_crypto_signatures {
#[link(wasm_import_module = "wasi_ephemeral_crypto_signatures")]
extern "C" {
pub fn signature_export(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn signature_import(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
arg5: i32,
) -> i32;
pub fn signature_state_open(arg0: i32, arg1: i32) -> i32;
pub fn signature_state_update(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn signature_state_sign(arg0: i32, arg1: i32) -> i32;
pub fn signature_state_close(arg0: i32) -> i32;
pub fn signature_verification_state_open(arg0: i32, arg1: i32) -> i32;
pub fn signature_verification_state_update(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn signature_verification_state_verify(arg0: i32, arg1: i32) -> i32;
pub fn signature_verification_state_close(arg0: i32) -> i32;
pub fn signature_close(arg0: i32) -> i32;
}
}
pub unsafe fn symmetric_key_generate(
algorithm: &str,
options: OptOptions,
) -> Result<SymmetricKey, CryptoErrno> {
let mut rp0 = MaybeUninit::<SymmetricKey>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_key_generate(
algorithm.as_ptr() as i32,
algorithm.len() as i32,
&options as *const _ as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SymmetricKey
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_key_import(
algorithm: &str,
raw: *const u8,
raw_len: Size,
) -> Result<SymmetricKey, CryptoErrno> {
let mut rp0 = MaybeUninit::<SymmetricKey>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_key_import(
algorithm.as_ptr() as i32,
algorithm.len() as i32,
raw as i32,
raw_len as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SymmetricKey
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_key_export(
symmetric_key: SymmetricKey,
) -> Result<ArrayOutput, CryptoErrno> {
let mut rp0 = MaybeUninit::<ArrayOutput>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_key_export(
symmetric_key as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const ArrayOutput
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_key_close(symmetric_key: SymmetricKey) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_symmetric::symmetric_key_close(symmetric_key as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_key_generate_managed(
secrets_manager: SecretsManager,
algorithm: &str,
options: OptOptions,
) -> Result<SymmetricKey, CryptoErrno> {
let mut rp0 = MaybeUninit::<SymmetricKey>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_key_generate_managed(
secrets_manager as i32,
algorithm.as_ptr() as i32,
algorithm.len() as i32,
&options as *const _ as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SymmetricKey
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_key_store_managed(
secrets_manager: SecretsManager,
symmetric_key: SymmetricKey,
symmetric_key_id: *mut u8,
symmetric_key_id_max_len: Size,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_symmetric::symmetric_key_store_managed(
secrets_manager as i32,
symmetric_key as i32,
symmetric_key_id as i32,
symmetric_key_id_max_len as i32,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_key_replace_managed(
secrets_manager: SecretsManager,
symmetric_key_old: SymmetricKey,
symmetric_key_new: SymmetricKey,
) -> Result<Version, CryptoErrno> {
let mut rp0 = MaybeUninit::<Version>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_key_replace_managed(
secrets_manager as i32,
symmetric_key_old as i32,
symmetric_key_new as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Version)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_key_id(
symmetric_key: SymmetricKey,
symmetric_key_id: *mut u8,
symmetric_key_id_max_len: Size,
) -> Result<(Size, Version), CryptoErrno> {
let mut rp0 = MaybeUninit::<Size>::uninit();
let mut rp1 = MaybeUninit::<Version>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_key_id(
symmetric_key as i32,
symmetric_key_id as i32,
symmetric_key_id_max_len as i32,
rp0.as_mut_ptr() as i32,
rp1.as_mut_ptr() as i32,
);
match ret {
0 => Ok((
core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size),
core::ptr::read(rp1.as_mut_ptr() as i32 as *const Version),
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_key_from_id(
secrets_manager: SecretsManager,
symmetric_key_id: *const u8,
symmetric_key_id_len: Size,
symmetric_key_version: Version,
) -> Result<SymmetricKey, CryptoErrno> {
let mut rp0 = MaybeUninit::<SymmetricKey>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_key_from_id(
secrets_manager as i32,
symmetric_key_id as i32,
symmetric_key_id_len as i32,
symmetric_key_version as i64,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SymmetricKey
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_open(
algorithm: &str,
key: OptSymmetricKey,
options: OptOptions,
) -> Result<SymmetricState, CryptoErrno> {
let mut rp0 = MaybeUninit::<SymmetricState>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_open(
algorithm.as_ptr() as i32,
algorithm.len() as i32,
&key as *const _ as i32,
&options as *const _ as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SymmetricState
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_options_get(
handle: SymmetricState,
name: &str,
value: *mut u8,
value_max_len: Size,
) -> Result<Size, CryptoErrno> {
let mut rp0 = MaybeUninit::<Size>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_options_get(
handle as i32,
name.as_ptr() as i32,
name.len() as i32,
value as i32,
value_max_len as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_options_get_u64(
handle: SymmetricState,
name: &str,
) -> Result<U64, CryptoErrno> {
let mut rp0 = MaybeUninit::<U64>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_options_get_u64(
handle as i32,
name.as_ptr() as i32,
name.len() as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const U64)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_clone(handle: SymmetricState) -> Result<SymmetricState, CryptoErrno> {
let mut rp0 = MaybeUninit::<SymmetricState>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_clone(
handle as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SymmetricState
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_close(handle: SymmetricState) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_close(handle as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_absorb(
handle: SymmetricState,
data: *const u8,
data_len: Size,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_absorb(
handle as i32,
data as i32,
data_len as i32,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_squeeze(
handle: SymmetricState,
out: *mut u8,
out_len: Size,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_squeeze(
handle as i32,
out as i32,
out_len as i32,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_squeeze_tag(
handle: SymmetricState,
) -> Result<SymmetricTag, CryptoErrno> {
let mut rp0 = MaybeUninit::<SymmetricTag>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_squeeze_tag(
handle as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SymmetricTag
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_squeeze_key(
handle: SymmetricState,
alg_str: &str,
) -> Result<SymmetricKey, CryptoErrno> {
let mut rp0 = MaybeUninit::<SymmetricKey>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_squeeze_key(
handle as i32,
alg_str.as_ptr() as i32,
alg_str.len() as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SymmetricKey
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_max_tag_len(handle: SymmetricState) -> Result<Size, CryptoErrno> {
let mut rp0 = MaybeUninit::<Size>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_max_tag_len(
handle as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_encrypt(
handle: SymmetricState,
out: *mut u8,
out_len: Size,
data: *const u8,
data_len: Size,
) -> Result<Size, CryptoErrno> {
let mut rp0 = MaybeUninit::<Size>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_encrypt(
handle as i32,
out as i32,
out_len as i32,
data as i32,
data_len as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_encrypt_detached(
handle: SymmetricState,
out: *mut u8,
out_len: Size,
data: *const u8,
data_len: Size,
) -> Result<SymmetricTag, CryptoErrno> {
let mut rp0 = MaybeUninit::<SymmetricTag>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_encrypt_detached(
handle as i32,
out as i32,
out_len as i32,
data as i32,
data_len as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const SymmetricTag
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_decrypt(
handle: SymmetricState,
out: *mut u8,
out_len: Size,
data: *const u8,
data_len: Size,
) -> Result<Size, CryptoErrno> {
let mut rp0 = MaybeUninit::<Size>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_decrypt(
handle as i32,
out as i32,
out_len as i32,
data as i32,
data_len as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_decrypt_detached(
handle: SymmetricState,
out: *mut u8,
out_len: Size,
data: *const u8,
data_len: Size,
raw_tag: *const u8,
raw_tag_len: Size,
) -> Result<Size, CryptoErrno> {
let mut rp0 = MaybeUninit::<Size>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_decrypt_detached(
handle as i32,
out as i32,
out_len as i32,
data as i32,
data_len as i32,
raw_tag as i32,
raw_tag_len as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_state_ratchet(handle: SymmetricState) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_symmetric::symmetric_state_ratchet(handle as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_tag_len(symmetric_tag: SymmetricTag) -> Result<Size, CryptoErrno> {
let mut rp0 = MaybeUninit::<Size>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_tag_len(
symmetric_tag as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_tag_pull(
symmetric_tag: SymmetricTag,
buf: *mut u8,
buf_len: Size,
) -> Result<Size, CryptoErrno> {
let mut rp0 = MaybeUninit::<Size>::uninit();
let ret = wasi_ephemeral_crypto_symmetric::symmetric_tag_pull(
symmetric_tag as i32,
buf as i32,
buf_len as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_tag_verify(
symmetric_tag: SymmetricTag,
expected_raw_tag_ptr: *const u8,
expected_raw_tag_len: Size,
) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_symmetric::symmetric_tag_verify(
symmetric_tag as i32,
expected_raw_tag_ptr as i32,
expected_raw_tag_len as i32,
);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn symmetric_tag_close(symmetric_tag: SymmetricTag) -> Result<(), CryptoErrno> {
let ret = wasi_ephemeral_crypto_symmetric::symmetric_tag_close(symmetric_tag as i32);
match ret {
0 => Ok(()),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub mod wasi_ephemeral_crypto_symmetric {
#[link(wasm_import_module = "wasi_ephemeral_crypto_symmetric")]
extern "C" {
pub fn symmetric_key_generate(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
pub fn symmetric_key_import(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32) -> i32;
pub fn symmetric_key_export(arg0: i32, arg1: i32) -> i32;
pub fn symmetric_key_close(arg0: i32) -> i32;
pub fn symmetric_key_generate_managed(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
) -> i32;
pub fn symmetric_key_store_managed(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
pub fn symmetric_key_replace_managed(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
pub fn symmetric_key_id(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32) -> i32;
pub fn symmetric_key_from_id(arg0: i32, arg1: i32, arg2: i32, arg3: i64, arg4: i32) -> i32;
pub fn symmetric_state_open(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32) -> i32;
pub fn symmetric_state_options_get(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
arg5: i32,
) -> i32;
pub fn symmetric_state_options_get_u64(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
pub fn symmetric_state_clone(arg0: i32, arg1: i32) -> i32;
pub fn symmetric_state_close(arg0: i32) -> i32;
pub fn symmetric_state_absorb(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn symmetric_state_squeeze(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn symmetric_state_squeeze_tag(arg0: i32, arg1: i32) -> i32;
pub fn symmetric_state_squeeze_key(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
pub fn symmetric_state_max_tag_len(arg0: i32, arg1: i32) -> i32;
pub fn symmetric_state_encrypt(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
arg5: i32,
) -> i32;
pub fn symmetric_state_encrypt_detached(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
arg5: i32,
) -> i32;
pub fn symmetric_state_decrypt(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
arg5: i32,
) -> i32;
pub fn symmetric_state_decrypt_detached(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
arg5: i32,
arg6: i32,
arg7: i32,
) -> i32;
pub fn symmetric_state_ratchet(arg0: i32) -> i32;
pub fn symmetric_tag_len(arg0: i32, arg1: i32) -> i32;
pub fn symmetric_tag_pull(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
pub fn symmetric_tag_verify(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn symmetric_tag_close(arg0: i32) -> i32;
}
}
pub unsafe fn kx_dh(pk: Publickey, sk: Secretkey) -> Result<ArrayOutput, CryptoErrno> {
let mut rp0 = MaybeUninit::<ArrayOutput>::uninit();
let ret = wasi_ephemeral_crypto_kx::kx_dh(pk as i32, sk as i32, rp0.as_mut_ptr() as i32);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const ArrayOutput
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn kx_encapsulate(pk: Publickey) -> Result<(ArrayOutput, ArrayOutput), CryptoErrno> {
let mut rp0 = MaybeUninit::<ArrayOutput>::uninit();
let mut rp1 = MaybeUninit::<ArrayOutput>::uninit();
let ret = wasi_ephemeral_crypto_kx::kx_encapsulate(
pk as i32,
rp0.as_mut_ptr() as i32,
rp1.as_mut_ptr() as i32,
);
match ret {
0 => Ok((
core::ptr::read(rp0.as_mut_ptr() as i32 as *const ArrayOutput),
core::ptr::read(rp1.as_mut_ptr() as i32 as *const ArrayOutput),
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub unsafe fn kx_decapsulate(
sk: Secretkey,
encapsulated_secret: *const u8,
encapsulated_secret_len: Size,
) -> Result<ArrayOutput, CryptoErrno> {
let mut rp0 = MaybeUninit::<ArrayOutput>::uninit();
let ret = wasi_ephemeral_crypto_kx::kx_decapsulate(
sk as i32,
encapsulated_secret as i32,
encapsulated_secret_len as i32,
rp0.as_mut_ptr() as i32,
);
match ret {
0 => Ok(core::ptr::read(
rp0.as_mut_ptr() as i32 as *const ArrayOutput
)),
_ => Err(CryptoErrno(ret as u16)),
}
}
pub mod wasi_ephemeral_crypto_kx {
#[link(wasm_import_module = "wasi_ephemeral_crypto_kx")]
extern "C" {
pub fn kx_dh(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn kx_encapsulate(arg0: i32, arg1: i32, arg2: i32) -> i32;
pub fn kx_decapsulate(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
}
}
pub const VERSION_UNSPECIFIED: Version = 18374686479671623680;
pub const VERSION_LATEST: Version = 18374686479671623681;
pub const VERSION_ALL: Version = 18374686479671623682;