Initial commit

This commit is contained in:
pjht 2023-08-28 09:12:36 -05:00
commit 3ddc7edfc5
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
17 changed files with 2126 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
/Cargo.lock

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "libfido2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libfido2-sys = { version = "0.2.0", path = "libfido2-sys" }
num_enum = "0.7.0"
paste = "1.0.14"
thiserror = "1.0.47"

244
func_avail Normal file
View File

@ -0,0 +1,244 @@
- fido_assert_allow_cred
- fido_assert_authdata_len
- fido_assert_authdata_ptr
- fido_assert_blob_len
- fido_assert_blob_ptr
- fido_assert_clientdata_hash_len
- fido_assert_clientdata_hash_ptr
- fido_assert_count
- fido_assert_empty_allow_list
- fido_assert_flags
- fido_assert_free
- fido_assert_hmac_secret_len
- fido_assert_hmac_secret_ptr
- fido_assert_id_len
- fido_assert_id_ptr
- fido_assert_largeblob_key_len
- fido_assert_largeblob_key_ptr
- fido_assert_new
- fido_assert_rp_id
- fido_assert_set_authdata
- fido_assert_set_authdata_raw
- fido_assert_set_clientdata
- fido_assert_set_clientdata_hash
- fido_assert_set_count
- fido_assert_set_extensions
- fido_assert_set_hmac_salt
- fido_assert_set_hmac_secret
- fido_assert_set_rp
- fido_assert_set_sig
- fido_assert_set_up
- fido_assert_set_uv
- fido_assert_sig_len
- fido_assert_sig_ptr
- fido_assert_sigcount
- fido_assert_user_display_name
- fido_assert_user_icon
- fido_assert_user_id_len
- fido_assert_user_id_ptr
- fido_assert_user_name
- fido_assert_verify
- fido_bio_dev_enroll_begin
- fido_bio_dev_enroll_cancel
- fido_bio_dev_enroll_continue
- fido_bio_dev_enroll_remove
- fido_bio_dev_get_info
- fido_bio_dev_get_template_array
- fido_bio_dev_set_template_name
- fido_bio_enroll_free
- fido_bio_enroll_last_status
- fido_bio_enroll_new
- fido_bio_enroll_remaining_samples
- fido_bio_info_free
- fido_bio_info_max_samples
- fido_bio_info_new
- fido_bio_info_type
- fido_bio_template
- fido_bio_template_array_count
- fido_bio_template_array_free
- fido_bio_template_array_new
- fido_bio_template_free
- fido_bio_template_id_len
- fido_bio_template_id_ptr
- fido_bio_template_name
- fido_bio_template_new
- fido_bio_template_set_id
- fido_bio_template_set_name
- fido_cbor_info_aaguid_len
- fido_cbor_info_aaguid_ptr
- fido_cbor_info_algorithm_cose
- fido_cbor_info_algorithm_count
- fido_cbor_info_algorithm_type
- fido_cbor_info_certs_len
- fido_cbor_info_certs_name_ptr
- fido_cbor_info_certs_value_ptr
- fido_cbor_info_extensions_len
- fido_cbor_info_extensions_ptr
- fido_cbor_info_free
- fido_cbor_info_fwversion
- fido_cbor_info_maxcredbloblen
- fido_cbor_info_maxcredcntlst
- fido_cbor_info_maxcredidlen
- fido_cbor_info_maxlargeblob
- fido_cbor_info_maxmsgsiz
- fido_cbor_info_maxrpid_minpinlen
- fido_cbor_info_minpinlen
- fido_cbor_info_new
- fido_cbor_info_new_pin_required
- fido_cbor_info_options_len
- fido_cbor_info_options_name_ptr
- fido_cbor_info_options_value_ptr
- fido_cbor_info_protocols_len
- fido_cbor_info_protocols_ptr
- fido_cbor_info_rk_remaining
- fido_cbor_info_transports_len
- fido_cbor_info_transports_ptr
- fido_cbor_info_uv_attempts
- fido_cbor_info_uv_modality
- fido_cbor_info_versions_len
- fido_cbor_info_versions_ptr
Y fido_cred_aaguid_len
Y fido_cred_aaguid_ptr
Y fido_cred_attstmt_len
Y fido_cred_attstmt_ptr
Y fido_cred_authdata_len
Y fido_cred_authdata_ptr
Y fido_cred_authdata_raw_len
Y fido_cred_authdata_raw_ptr
Y fido_cred_clientdata_hash_len
Y fido_cred_clientdata_hash_ptr
Y fido_cred_display_name
- fido_cred_empty_exclude_list
Y fido_cred_exclude
P fido_cred_flags
P fido_cred_fmt
Y fido_cred_free
Y fido_cred_id_len
Y fido_cred_id_ptr
Y fido_cred_largeblob_key_len
Y fido_cred_largeblob_key_ptr
Y fido_cred_new
Y fido_cred_pin_minlen
Y fido_cred_prot
Y fido_cred_pubkey_len
Y fido_cred_pubkey_ptr
Y fido_cred_rp_id
Y fido_cred_rp_name
Y fido_cred_set_attstmt
Y fido_cred_set_authdata
Y fido_cred_set_authdata_raw
Y fido_cred_set_blob
Y fido_cred_set_clientdata
Y fido_cred_set_clientdata_hash
Y fido_cred_set_extensions
P fido_cred_set_fmt
Y fido_cred_set_id
Y fido_cred_set_pin_minlen
Y fido_cred_set_prot
Y fido_cred_set_rk
Y fido_cred_set_rp
Y fido_cred_set_sig
Y fido_cred_set_type
Y fido_cred_set_user
Y fido_cred_set_uv
Y fido_cred_set_x509
Y fido_cred_sig_len
Y fido_cred_sig_ptr
Y fido_cred_sigcount
Y fido_cred_type
Y fido_cred_user_id_len
Y fido_cred_user_id_ptr
Y fido_cred_user_name
Y fido_cred_verify
Y fido_cred_verify_self
Y fido_cred_x5c_len
Y fido_cred_x5c_ptr
- fido_credman_del_dev_rk
- fido_credman_get_dev_metadata
- fido_credman_get_dev_rk
- fido_credman_get_dev_rp
- fido_credman_metadata_free
- fido_credman_metadata_new
- fido_credman_rk
- fido_credman_rk_count
- fido_credman_rk_existing
- fido_credman_rk_free
- fido_credman_rk_new
- fido_credman_rk_remaining
- fido_credman_rp_count
- fido_credman_rp_free
- fido_credman_rp_id
- fido_credman_rp_id_hash_len
- fido_credman_rp_id_hash_ptr
- fido_credman_rp_name
- fido_credman_rp_new
- fido_credman_set_dev_rk
Y fido_dev_info_free
Y fido_dev_info_manifest
Y fido_dev_info_manufacturer_string
Y fido_dev_info_new
Y fido_dev_info_path
Y fido_dev_info_product
Y fido_dev_info_product_string
Y fido_dev_info_ptr
- fido_dev_info_set
Y fido_dev_info_vendor
Y fido_dev_build
- fido_dev_cancel
Y fido_dev_close
- fido_dev_enable_entattest
P fido_dev_flags
Y fido_dev_force_fido2
- fido_dev_force_pin_change
Y fido_dev_force_u2f
Y fido_dev_free
Y fido_dev_get_assert
- fido_dev_get_cbor_info
Y fido_dev_get_retry_count
- fido_dev_get_touch_begin
- fido_dev_get_touch_status
Y fido_dev_get_uv_retry_count
Y fido_dev_has_pin
Y fido_dev_has_uv
- fido_dev_io_handle
Y fido_dev_is_fido2
Y fido_dev_is_winhello
- fido_dev_largeblob_get
- fido_dev_largeblob_get_array
- fido_dev_largeblob_remove
- fido_dev_largeblob_set
- fido_dev_largeblob_set_array
Y fido_dev_major
Y fido_dev_make_cred
Y fido_dev_minor
Y fido_dev_new
- fido_dev_new_with_info
Y fido_dev_open
- fido_dev_open_with_info
Y fido_dev_protocol
Y fido_dev_reset
- fido_dev_set_io_functions
Y fido_dev_set_pin
- fido_dev_set_pin_minlen
- fido_dev_set_pin_minlen_rpid
- fido_dev_set_sigmask
- fido_dev_set_timeout
- fido_dev_set_transport_functions
Y fido_dev_supports_cred_prot
Y fido_dev_supports_credman
Y fido_dev_supports_permissions
Y fido_dev_supports_pin
Y fido_dev_supports_uv
- fido_dev_toggle_always_uv
Y fido_init
- fido_set_log_handler
Y fido_strerr

25
libfido2-sys/Cargo.toml Normal file
View File

@ -0,0 +1,25 @@
[package]
name = "libfido2-sys"
version = "0.2.0"
authors = ["tyan boot <tyanboot@outlook.com>"]
license = "MIT"
description = "FFI bindings to Yubico fido2"
repository = "https://github.com/tyan-boot/fido-rs"
keywords = ["fido2", "webauthn"]
categories = ["external-ffi-bindings"]
edition = "2021"
links = "fido2"
build = "build.rs"
[dependencies]
[build-dependencies]
anyhow = "1.0.66"
cfg-if = "1.0.0"
[target.'cfg(target_env = "msvc")'.build-dependencies]
vcpkg = "0.2.15"
[target.'cfg(not(target_env = "msvc"))'.build-dependencies]
pkg-config = "0.3.26"

21
libfido2-sys/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 tyan boot
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

6
libfido2-sys/README.MD Normal file
View File

@ -0,0 +1,6 @@
# libfido2-sys
[![crates.io](https://img.shields.io/crates/v/libfido2-sys?style=flat-square)](https://crates.io/crates/libfido2-sys)
[![MIT](https://img.shields.io/crates/l/libfido2-sys?style=flat-square)](./LICENSE)
FFI bindings to Yubico [libfido2](https://github.com/Yubico/libfido2)

57
libfido2-sys/build.rs Normal file
View File

@ -0,0 +1,57 @@
use anyhow::Result;
use cfg_if::cfg_if;
use std::env;
fn main() -> Result<()> {
println!("cargo:rerun-if-env-changed=FIDO2_LIB_DIR");
println!("cargo:rerun-if-env-changed=FIDO2_USE_PKG_CONFIG");
if let Ok(dir) = env::var("FIDO2_LIB_DIR") {
println!("cargo:rustc-link-search={}", dir);
println!("cargo:rustc-link-lib=static=fido2");
if cfg!(windows) {
println!("cargo:rustc-link-lib=hid");
println!("cargo:rustc-link-lib=user32");
println!("cargo:rustc-link-lib=setupapi");
println!("cargo:rustc-link-lib=crypt32");
}
cfg_if! {
if #[cfg(all(windows, target_env = "msvc"))] {
// link to pre-build cbor,zlib,crypto
println!("cargo:rustc-link-lib=cbor");
println!("cargo:rustc-link-lib=zlib1");
println!("cargo:rustc-link-lib=crypto-49");
} else {
println!("cargo:rustc-link-lib=cbor");
println!("cargo:rustc-link-lib=z");
println!("cargo:rustc-link-lib=crypto");
}
}
return Ok(());
}
find_pkg()
}
#[cfg(not(target_env = "msvc"))]
fn find_pkg() -> Result<()> {
let _lib = pkg_config::probe_library("libfido2")?;
Ok(())
}
#[cfg(all(windows, target_env = "msvc"))]
fn find_pkg() -> Result<()> {
let _lib = vcpkg::find_package("libfido2")?;
println!("cargo:rustc-link-lib=hid");
println!("cargo:rustc-link-lib=user32");
println!("cargo:rustc-link-lib=setupapi");
println!("cargo:rustc-link-lib=crypt32");
Ok(())
}

View File

@ -0,0 +1,5 @@
#include <fido.h>
#include <fido/rs256.h>
#include <fido/es256.h>
#include <fido/es384.h>
#include <fido/eddsa.h>

BIN
libfido2-sys/help.txt Normal file

Binary file not shown.

856
libfido2-sys/src/ffi.rs Normal file
View File

@ -0,0 +1,856 @@
/* automatically generated by rust-bindgen 0.63.0 */
pub const FIDO_ERR_SUCCESS: i32 = 0;
pub const FIDO_ERR_INVALID_COMMAND: i32 = 1;
pub const FIDO_ERR_INVALID_PARAMETER: i32 = 2;
pub const FIDO_ERR_INVALID_LENGTH: i32 = 3;
pub const FIDO_ERR_INVALID_SEQ: i32 = 4;
pub const FIDO_ERR_TIMEOUT: i32 = 5;
pub const FIDO_ERR_CHANNEL_BUSY: i32 = 6;
pub const FIDO_ERR_LOCK_REQUIRED: i32 = 10;
pub const FIDO_ERR_INVALID_CHANNEL: i32 = 11;
pub const FIDO_ERR_CBOR_UNEXPECTED_TYPE: i32 = 17;
pub const FIDO_ERR_INVALID_CBOR: i32 = 18;
pub const FIDO_ERR_MISSING_PARAMETER: i32 = 20;
pub const FIDO_ERR_LIMIT_EXCEEDED: i32 = 21;
pub const FIDO_ERR_UNSUPPORTED_EXTENSION: i32 = 22;
pub const FIDO_ERR_FP_DATABASE_FULL: i32 = 23;
pub const FIDO_ERR_LARGEBLOB_STORAGE_FULL: i32 = 24;
pub const FIDO_ERR_CREDENTIAL_EXCLUDED: i32 = 25;
pub const FIDO_ERR_PROCESSING: i32 = 33;
pub const FIDO_ERR_INVALID_CREDENTIAL: i32 = 34;
pub const FIDO_ERR_USER_ACTION_PENDING: i32 = 35;
pub const FIDO_ERR_OPERATION_PENDING: i32 = 36;
pub const FIDO_ERR_NO_OPERATIONS: i32 = 37;
pub const FIDO_ERR_UNSUPPORTED_ALGORITHM: i32 = 38;
pub const FIDO_ERR_OPERATION_DENIED: i32 = 39;
pub const FIDO_ERR_KEY_STORE_FULL: i32 = 40;
pub const FIDO_ERR_NOT_BUSY: i32 = 41;
pub const FIDO_ERR_NO_OPERATION_PENDING: i32 = 42;
pub const FIDO_ERR_UNSUPPORTED_OPTION: i32 = 43;
pub const FIDO_ERR_INVALID_OPTION: i32 = 44;
pub const FIDO_ERR_KEEPALIVE_CANCEL: i32 = 45;
pub const FIDO_ERR_NO_CREDENTIALS: i32 = 46;
pub const FIDO_ERR_USER_ACTION_TIMEOUT: i32 = 47;
pub const FIDO_ERR_NOT_ALLOWED: i32 = 48;
pub const FIDO_ERR_PIN_INVALID: i32 = 49;
pub const FIDO_ERR_PIN_BLOCKED: i32 = 50;
pub const FIDO_ERR_PIN_AUTH_INVALID: i32 = 51;
pub const FIDO_ERR_PIN_AUTH_BLOCKED: i32 = 52;
pub const FIDO_ERR_PIN_NOT_SET: i32 = 53;
pub const FIDO_ERR_PIN_REQUIRED: i32 = 54;
pub const FIDO_ERR_PIN_POLICY_VIOLATION: i32 = 55;
pub const FIDO_ERR_PIN_TOKEN_EXPIRED: i32 = 56;
pub const FIDO_ERR_REQUEST_TOO_LARGE: i32 = 57;
pub const FIDO_ERR_ACTION_TIMEOUT: i32 = 58;
pub const FIDO_ERR_UP_REQUIRED: i32 = 59;
pub const FIDO_ERR_UV_BLOCKED: i32 = 60;
pub const FIDO_ERR_UV_INVALID: i32 = 63;
pub const FIDO_ERR_UNAUTHORIZED_PERM: i32 = 64;
pub const FIDO_ERR_ERR_OTHER: i32 = 127;
pub const FIDO_ERR_SPEC_LAST: i32 = 223;
pub const FIDO_OK: i32 = 0;
pub const FIDO_ERR_TX: i32 = -1;
pub const FIDO_ERR_RX: i32 = -2;
pub const FIDO_ERR_RX_NOT_CBOR: i32 = -3;
pub const FIDO_ERR_RX_INVALID_CBOR: i32 = -4;
pub const FIDO_ERR_INVALID_PARAM: i32 = -5;
pub const FIDO_ERR_INVALID_SIG: i32 = -6;
pub const FIDO_ERR_INVALID_ARGUMENT: i32 = -7;
pub const FIDO_ERR_USER_PRESENCE_REQUIRED: i32 = -8;
pub const FIDO_ERR_INTERNAL: i32 = -9;
pub const FIDO_ERR_NOTFOUND: i32 = -10;
pub const FIDO_ERR_COMPRESS: i32 = -11;
pub const CTAP_AUTHDATA_USER_PRESENT: i32 = 1;
pub const CTAP_AUTHDATA_USER_VERIFIED: i32 = 4;
pub const CTAP_AUTHDATA_ATT_CRED: i32 = 64;
pub const CTAP_AUTHDATA_EXT_DATA: i32 = 128;
pub const CTAP_CMD_PING: i32 = 1;
pub const CTAP_CMD_MSG: i32 = 3;
pub const CTAP_CMD_LOCK: i32 = 4;
pub const CTAP_CMD_INIT: i32 = 6;
pub const CTAP_CMD_WINK: i32 = 8;
pub const CTAP_CMD_CBOR: i32 = 16;
pub const CTAP_CMD_CANCEL: i32 = 17;
pub const CTAP_KEEPALIVE: i32 = 59;
pub const CTAP_FRAME_INIT: i32 = 128;
pub const CTAP_CBOR_MAKECRED: i32 = 1;
pub const CTAP_CBOR_ASSERT: i32 = 2;
pub const CTAP_CBOR_GETINFO: i32 = 4;
pub const CTAP_CBOR_CLIENT_PIN: i32 = 6;
pub const CTAP_CBOR_RESET: i32 = 7;
pub const CTAP_CBOR_NEXT_ASSERT: i32 = 8;
pub const CTAP_CBOR_LARGEBLOB: i32 = 12;
pub const CTAP_CBOR_CONFIG: i32 = 13;
pub const CTAP_CBOR_BIO_ENROLL_PRE: i32 = 64;
pub const CTAP_CBOR_CRED_MGMT_PRE: i32 = 65;
pub const CTAP_PIN_PROTOCOL1: i32 = 1;
pub const CTAP_PIN_PROTOCOL2: i32 = 2;
pub const U2F_CMD_REGISTER: i32 = 1;
pub const U2F_CMD_AUTH: i32 = 2;
pub const U2F_AUTH_SIGN: i32 = 3;
pub const U2F_AUTH_CHECK: i32 = 7;
pub const CTAP_CID_BROADCAST: i64 = 4294967295;
pub const CTAP_INIT_HEADER_LEN: i32 = 7;
pub const CTAP_CONT_HEADER_LEN: i32 = 5;
pub const CTAP_MAX_REPORT_LEN: i32 = 64;
pub const CTAP_MIN_REPORT_LEN: i32 = 8;
pub const FIDO_RANDOM_DEV: &[u8; 13usize] = b"/dev/urandom\0";
pub const FIDO_MAXMSG: i32 = 2048;
pub const FIDO_CAP_WINK: i32 = 1;
pub const FIDO_CAP_CBOR: i32 = 4;
pub const FIDO_CAP_NMSG: i32 = 8;
pub const COSE_UNSPEC: i32 = 0;
pub const COSE_ES256: i32 = -7;
pub const COSE_EDDSA: i32 = -8;
pub const COSE_ECDH_ES256: i32 = -25;
pub const COSE_ES384: i32 = -35;
pub const COSE_RS256: i32 = -257;
pub const COSE_RS1: i32 = -65535;
pub const COSE_KTY_OKP: i32 = 1;
pub const COSE_KTY_EC2: i32 = 2;
pub const COSE_KTY_RSA: i32 = 3;
pub const COSE_P256: i32 = 1;
pub const COSE_P384: i32 = 2;
pub const COSE_ED25519: i32 = 6;
pub const FIDO_EXT_HMAC_SECRET: i32 = 1;
pub const FIDO_EXT_CRED_PROTECT: i32 = 2;
pub const FIDO_EXT_LARGEBLOB_KEY: i32 = 4;
pub const FIDO_EXT_CRED_BLOB: i32 = 8;
pub const FIDO_EXT_MINPINLEN: i32 = 16;
pub const FIDO_CRED_PROT_UV_OPTIONAL: i32 = 1;
pub const FIDO_CRED_PROT_UV_OPTIONAL_WITH_ID: i32 = 2;
pub const FIDO_CRED_PROT_UV_REQUIRED: i32 = 3;
pub const FIDO_UV_MODE_TUP: i32 = 1;
pub const FIDO_UV_MODE_FP: i32 = 2;
pub const FIDO_UV_MODE_PIN: i32 = 4;
pub const FIDO_UV_MODE_VOICE: i32 = 8;
pub const FIDO_UV_MODE_FACE: i32 = 16;
pub const FIDO_UV_MODE_LOCATION: i32 = 32;
pub const FIDO_UV_MODE_EYE: i32 = 64;
pub const FIDO_UV_MODE_DRAWN: i32 = 128;
pub const FIDO_UV_MODE_HAND: i32 = 256;
pub const FIDO_UV_MODE_NONE: i32 = 512;
pub const FIDO_UV_MODE_ALL: i32 = 1024;
pub const FIDO_UV_MODE_EXT_PIN: i32 = 2048;
pub const FIDO_UV_MODE_EXT_DRAWN: i32 = 4096;
pub const FIDO_DEBUG: i32 = 1;
pub const FIDO_DISABLE_U2F_FALLBACK: i32 = 2;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct evp_pkey_st {
_unused: [u8; 0],
}
pub type EVP_PKEY = evp_pkey_st;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct rsa_st {
_unused: [u8; 0],
}
pub type RSA = rsa_st;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ec_key_st {
_unused: [u8; 0],
}
pub type EC_KEY = ec_key_st;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct fido_dev {
_unused: [u8; 0],
}
pub type fido_dev_io_open_t = ::std::option::Option<
unsafe extern "C" fn(arg1: *const ::std::os::raw::c_char) -> *mut ::std::os::raw::c_void,
>;
pub type fido_dev_io_close_t =
::std::option::Option<unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void)>;
pub type fido_dev_io_read_t = ::std::option::Option<
unsafe extern "C" fn(
arg1: *mut ::std::os::raw::c_void,
arg2: *mut ::std::os::raw::c_uchar,
arg3: usize,
arg4: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int,
>;
pub type fido_dev_io_write_t = ::std::option::Option<
unsafe extern "C" fn(
arg1: *mut ::std::os::raw::c_void,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int,
>;
pub type fido_dev_rx_t = ::std::option::Option<
unsafe extern "C" fn(
arg1: *mut fido_dev,
arg2: u8,
arg3: *mut ::std::os::raw::c_uchar,
arg4: usize,
arg5: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int,
>;
pub type fido_dev_tx_t = ::std::option::Option<
unsafe extern "C" fn(
arg1: *mut fido_dev,
arg2: u8,
arg3: *const ::std::os::raw::c_uchar,
arg4: usize,
) -> ::std::os::raw::c_int,
>;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct fido_dev_io {
pub open: fido_dev_io_open_t,
pub close: fido_dev_io_close_t,
pub read: fido_dev_io_read_t,
pub write: fido_dev_io_write_t,
}
#[test]
fn bindgen_test_layout_fido_dev_io() {
const UNINIT: ::std::mem::MaybeUninit<fido_dev_io> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<fido_dev_io>(),
32usize,
concat!("Size of: ", stringify!(fido_dev_io))
);
assert_eq!(
::std::mem::align_of::<fido_dev_io>(),
8usize,
concat!("Alignment of ", stringify!(fido_dev_io))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).open) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(fido_dev_io),
"::",
stringify!(open)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).close) as usize - ptr as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(fido_dev_io),
"::",
stringify!(close)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(fido_dev_io),
"::",
stringify!(read)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize },
24usize,
concat!(
"Offset of field: ",
stringify!(fido_dev_io),
"::",
stringify!(write)
)
);
}
pub type fido_dev_io_t = fido_dev_io;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct fido_dev_transport {
pub rx: fido_dev_rx_t,
pub tx: fido_dev_tx_t,
}
#[test]
fn bindgen_test_layout_fido_dev_transport() {
const UNINIT: ::std::mem::MaybeUninit<fido_dev_transport> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<fido_dev_transport>(),
16usize,
concat!("Size of: ", stringify!(fido_dev_transport))
);
assert_eq!(
::std::mem::align_of::<fido_dev_transport>(),
8usize,
concat!("Alignment of ", stringify!(fido_dev_transport))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).rx) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(fido_dev_transport),
"::",
stringify!(rx)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).tx) as usize - ptr as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(fido_dev_transport),
"::",
stringify!(tx)
)
);
}
pub type fido_dev_transport_t = fido_dev_transport;
pub const fido_opt_t_FIDO_OPT_OMIT: fido_opt_t = 0;
pub const fido_opt_t_FIDO_OPT_FALSE: fido_opt_t = 1;
pub const fido_opt_t_FIDO_OPT_TRUE: fido_opt_t = 2;
pub type fido_opt_t = ::std::os::raw::c_int;
pub type fido_log_handler_t =
::std::option::Option<unsafe extern "C" fn(arg1: *const ::std::os::raw::c_char)>;
pub type fido_sigset_t = ::std::os::raw::c_int;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct fido_assert {
_unused: [u8; 0],
}
pub type fido_assert_t = fido_assert;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct fido_cbor_info {
_unused: [u8; 0],
}
pub type fido_cbor_info_t = fido_cbor_info;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct fido_cred {
_unused: [u8; 0],
}
pub type fido_cred_t = fido_cred;
pub type fido_dev_t = fido_dev;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct fido_dev_info {
_unused: [u8; 0],
}
pub type fido_dev_info_t = fido_dev_info;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct es256_pk {
_unused: [u8; 0],
}
pub type es256_pk_t = es256_pk;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct es384_pk {
_unused: [u8; 0],
}
pub type es384_pk_t = es384_pk;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct rs256_pk {
_unused: [u8; 0],
}
pub type rs256_pk_t = rs256_pk;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct eddsa_pk {
_unused: [u8; 0],
}
pub type eddsa_pk_t = eddsa_pk;
extern "C" {
pub fn fido_strerr(arg1: ::std::os::raw::c_int) -> *const ::std::os::raw::c_char;
pub fn fido_assert_new() -> *mut fido_assert_t;
pub fn fido_cred_new() -> *mut fido_cred_t;
pub fn fido_dev_new() -> *mut fido_dev_t;
pub fn fido_dev_new_with_info(arg1: *const fido_dev_info_t) -> *mut fido_dev_t;
pub fn fido_dev_info_new(arg1: usize) -> *mut fido_dev_info_t;
pub fn fido_cbor_info_new() -> *mut fido_cbor_info_t;
pub fn fido_dev_io_handle(arg1: *const fido_dev_t) -> *mut ::std::os::raw::c_void;
pub fn fido_assert_free(arg1: *mut *mut fido_assert_t);
pub fn fido_cbor_info_free(arg1: *mut *mut fido_cbor_info_t);
pub fn fido_cred_free(arg1: *mut *mut fido_cred_t);
pub fn fido_dev_force_fido2(arg1: *mut fido_dev_t);
pub fn fido_dev_force_u2f(arg1: *mut fido_dev_t);
pub fn fido_dev_free(arg1: *mut *mut fido_dev_t);
pub fn fido_dev_info_free(arg1: *mut *mut fido_dev_info_t, arg2: usize);
pub fn fido_init(arg1: ::std::os::raw::c_int);
pub fn fido_set_log_handler(arg1: fido_log_handler_t);
pub fn fido_assert_authdata_ptr(
arg1: *const fido_assert_t,
arg2: usize,
) -> *const ::std::os::raw::c_uchar;
pub fn fido_assert_clientdata_hash_ptr(
arg1: *const fido_assert_t,
) -> *const ::std::os::raw::c_uchar;
pub fn fido_assert_hmac_secret_ptr(
arg1: *const fido_assert_t,
arg2: usize,
) -> *const ::std::os::raw::c_uchar;
pub fn fido_assert_id_ptr(
arg1: *const fido_assert_t,
arg2: usize,
) -> *const ::std::os::raw::c_uchar;
pub fn fido_assert_largeblob_key_ptr(
arg1: *const fido_assert_t,
arg2: usize,
) -> *const ::std::os::raw::c_uchar;
pub fn fido_assert_sig_ptr(
arg1: *const fido_assert_t,
arg2: usize,
) -> *const ::std::os::raw::c_uchar;
pub fn fido_assert_user_id_ptr(
arg1: *const fido_assert_t,
arg2: usize,
) -> *const ::std::os::raw::c_uchar;
pub fn fido_assert_blob_ptr(
arg1: *const fido_assert_t,
arg2: usize,
) -> *const ::std::os::raw::c_uchar;
pub fn fido_cbor_info_certs_name_ptr(
arg1: *const fido_cbor_info_t,
) -> *mut *mut ::std::os::raw::c_char;
pub fn fido_cbor_info_extensions_ptr(
arg1: *const fido_cbor_info_t,
) -> *mut *mut ::std::os::raw::c_char;
pub fn fido_cbor_info_options_name_ptr(
arg1: *const fido_cbor_info_t,
) -> *mut *mut ::std::os::raw::c_char;
pub fn fido_cbor_info_transports_ptr(
arg1: *const fido_cbor_info_t,
) -> *mut *mut ::std::os::raw::c_char;
pub fn fido_cbor_info_versions_ptr(
arg1: *const fido_cbor_info_t,
) -> *mut *mut ::std::os::raw::c_char;
pub fn fido_cbor_info_options_value_ptr(arg1: *const fido_cbor_info_t) -> *const bool;
pub fn fido_assert_rp_id(arg1: *const fido_assert_t) -> *const ::std::os::raw::c_char;
pub fn fido_assert_user_display_name(
arg1: *const fido_assert_t,
arg2: usize,
) -> *const ::std::os::raw::c_char;
pub fn fido_assert_user_icon(
arg1: *const fido_assert_t,
arg2: usize,
) -> *const ::std::os::raw::c_char;
pub fn fido_assert_user_name(
arg1: *const fido_assert_t,
arg2: usize,
) -> *const ::std::os::raw::c_char;
pub fn fido_cbor_info_algorithm_type(
arg1: *const fido_cbor_info_t,
arg2: usize,
) -> *const ::std::os::raw::c_char;
pub fn fido_cred_display_name(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_char;
pub fn fido_cred_fmt(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_char;
pub fn fido_cred_rp_id(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_char;
pub fn fido_cred_rp_name(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_char;
pub fn fido_cred_user_name(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_char;
pub fn fido_dev_info_manufacturer_string(
arg1: *const fido_dev_info_t,
) -> *const ::std::os::raw::c_char;
pub fn fido_dev_info_path(arg1: *const fido_dev_info_t) -> *const ::std::os::raw::c_char;
pub fn fido_dev_info_product_string(
arg1: *const fido_dev_info_t,
) -> *const ::std::os::raw::c_char;
pub fn fido_dev_info_ptr(arg1: *const fido_dev_info_t, arg2: usize) -> *const fido_dev_info_t;
pub fn fido_cbor_info_protocols_ptr(arg1: *const fido_cbor_info_t) -> *const u8;
pub fn fido_cbor_info_certs_value_ptr(arg1: *const fido_cbor_info_t) -> *const u64;
pub fn fido_cbor_info_aaguid_ptr(
arg1: *const fido_cbor_info_t,
) -> *const ::std::os::raw::c_uchar;
pub fn fido_cred_aaguid_ptr(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_uchar;
pub fn fido_cred_attstmt_ptr(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_uchar;
pub fn fido_cred_authdata_ptr(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_uchar;
pub fn fido_cred_authdata_raw_ptr(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_uchar;
pub fn fido_cred_clientdata_hash_ptr(
arg1: *const fido_cred_t,
) -> *const ::std::os::raw::c_uchar;
pub fn fido_cred_id_ptr(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_uchar;
pub fn fido_cred_largeblob_key_ptr(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_uchar;
pub fn fido_cred_pubkey_ptr(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_uchar;
pub fn fido_cred_sig_ptr(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_uchar;
pub fn fido_cred_user_id_ptr(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_uchar;
pub fn fido_cred_x5c_ptr(arg1: *const fido_cred_t) -> *const ::std::os::raw::c_uchar;
pub fn fido_assert_allow_cred(
arg1: *mut fido_assert_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_assert_set_authdata(
arg1: *mut fido_assert_t,
arg2: usize,
arg3: *const ::std::os::raw::c_uchar,
arg4: usize,
) -> ::std::os::raw::c_int;
pub fn fido_assert_set_authdata_raw(
arg1: *mut fido_assert_t,
arg2: usize,
arg3: *const ::std::os::raw::c_uchar,
arg4: usize,
) -> ::std::os::raw::c_int;
pub fn fido_assert_set_clientdata(
arg1: *mut fido_assert_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_assert_set_clientdata_hash(
arg1: *mut fido_assert_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_assert_set_count(arg1: *mut fido_assert_t, arg2: usize) -> ::std::os::raw::c_int;
pub fn fido_assert_set_extensions(
arg1: *mut fido_assert_t,
arg2: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int;
pub fn fido_assert_set_hmac_salt(
arg1: *mut fido_assert_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_assert_set_hmac_secret(
arg1: *mut fido_assert_t,
arg2: usize,
arg3: *const ::std::os::raw::c_uchar,
arg4: usize,
) -> ::std::os::raw::c_int;
pub fn fido_assert_set_options(
arg1: *mut fido_assert_t,
arg2: bool,
arg3: bool,
) -> ::std::os::raw::c_int;
pub fn fido_assert_set_rp(
arg1: *mut fido_assert_t,
arg2: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
pub fn fido_assert_set_up(arg1: *mut fido_assert_t, arg2: fido_opt_t) -> ::std::os::raw::c_int;
pub fn fido_assert_set_uv(arg1: *mut fido_assert_t, arg2: fido_opt_t) -> ::std::os::raw::c_int;
pub fn fido_assert_set_sig(
arg1: *mut fido_assert_t,
arg2: usize,
arg3: *const ::std::os::raw::c_uchar,
arg4: usize,
) -> ::std::os::raw::c_int;
pub fn fido_assert_verify(
arg1: *const fido_assert_t,
arg2: usize,
arg3: ::std::os::raw::c_int,
arg4: *const ::std::os::raw::c_void,
) -> ::std::os::raw::c_int;
pub fn fido_cbor_info_algorithm_cose(
arg1: *const fido_cbor_info_t,
arg2: usize,
) -> ::std::os::raw::c_int;
pub fn fido_cred_exclude(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_cred_prot(arg1: *const fido_cred_t) -> ::std::os::raw::c_int;
pub fn fido_cred_set_attstmt(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_authdata(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_authdata_raw(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_blob(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_clientdata(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_clientdata_hash(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_extensions(
arg1: *mut fido_cred_t,
arg2: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_fmt(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_id(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_options(
arg1: *mut fido_cred_t,
arg2: bool,
arg3: bool,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_pin_minlen(arg1: *mut fido_cred_t, arg2: usize) -> ::std::os::raw::c_int;
pub fn fido_cred_set_prot(
arg1: *mut fido_cred_t,
arg2: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_rk(arg1: *mut fido_cred_t, arg2: fido_opt_t) -> ::std::os::raw::c_int;
pub fn fido_cred_set_rp(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_char,
arg3: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_sig(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_type(
arg1: *mut fido_cred_t,
arg2: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_uv(arg1: *mut fido_cred_t, arg2: fido_opt_t) -> ::std::os::raw::c_int;
pub fn fido_cred_type(arg1: *const fido_cred_t) -> ::std::os::raw::c_int;
pub fn fido_cred_set_user(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
arg4: *const ::std::os::raw::c_char,
arg5: *const ::std::os::raw::c_char,
arg6: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
pub fn fido_cred_set_x509(
arg1: *mut fido_cred_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn fido_cred_verify(arg1: *const fido_cred_t) -> ::std::os::raw::c_int;
pub fn fido_cred_verify_self(arg1: *const fido_cred_t) -> ::std::os::raw::c_int;
pub fn fido_dev_set_sigmask(
arg1: *mut fido_dev_t,
arg2: *const fido_sigset_t,
) -> ::std::os::raw::c_int;
pub fn fido_dev_cancel(arg1: *mut fido_dev_t) -> ::std::os::raw::c_int;
pub fn fido_dev_close(arg1: *mut fido_dev_t) -> ::std::os::raw::c_int;
pub fn fido_dev_get_assert(
arg1: *mut fido_dev_t,
arg2: *mut fido_assert_t,
arg3: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
pub fn fido_dev_get_cbor_info(
arg1: *mut fido_dev_t,
arg2: *mut fido_cbor_info_t,
) -> ::std::os::raw::c_int;
pub fn fido_dev_get_retry_count(
arg1: *mut fido_dev_t,
arg2: *mut ::std::os::raw::c_int,
) -> ::std::os::raw::c_int;
pub fn fido_dev_get_uv_retry_count(
arg1: *mut fido_dev_t,
arg2: *mut ::std::os::raw::c_int,
) -> ::std::os::raw::c_int;
pub fn fido_dev_get_touch_begin(arg1: *mut fido_dev_t) -> ::std::os::raw::c_int;
pub fn fido_dev_get_touch_status(
arg1: *mut fido_dev_t,
arg2: *mut ::std::os::raw::c_int,
arg3: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int;
pub fn fido_dev_info_manifest(
arg1: *mut fido_dev_info_t,
arg2: usize,
arg3: *mut usize,
) -> ::std::os::raw::c_int;
pub fn fido_dev_info_set(
arg1: *mut fido_dev_info_t,
arg2: usize,
arg3: *const ::std::os::raw::c_char,
arg4: *const ::std::os::raw::c_char,
arg5: *const ::std::os::raw::c_char,
arg6: *const fido_dev_io_t,
arg7: *const fido_dev_transport_t,
) -> ::std::os::raw::c_int;
pub fn fido_dev_make_cred(
arg1: *mut fido_dev_t,
arg2: *mut fido_cred_t,
arg3: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
pub fn fido_dev_open_with_info(arg1: *mut fido_dev_t) -> ::std::os::raw::c_int;
pub fn fido_dev_open(
arg1: *mut fido_dev_t,
arg2: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
pub fn fido_dev_reset(arg1: *mut fido_dev_t) -> ::std::os::raw::c_int;
pub fn fido_dev_set_io_functions(
arg1: *mut fido_dev_t,
arg2: *const fido_dev_io_t,
) -> ::std::os::raw::c_int;
pub fn fido_dev_set_pin(
arg1: *mut fido_dev_t,
arg2: *const ::std::os::raw::c_char,
arg3: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
pub fn fido_dev_set_transport_functions(
arg1: *mut fido_dev_t,
arg2: *const fido_dev_transport_t,
) -> ::std::os::raw::c_int;
pub fn fido_dev_set_timeout(
arg1: *mut fido_dev_t,
arg2: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int;
pub fn fido_assert_authdata_len(arg1: *const fido_assert_t, arg2: usize) -> usize;
pub fn fido_assert_clientdata_hash_len(arg1: *const fido_assert_t) -> usize;
pub fn fido_assert_count(arg1: *const fido_assert_t) -> usize;
pub fn fido_assert_hmac_secret_len(arg1: *const fido_assert_t, arg2: usize) -> usize;
pub fn fido_assert_id_len(arg1: *const fido_assert_t, arg2: usize) -> usize;
pub fn fido_assert_largeblob_key_len(arg1: *const fido_assert_t, arg2: usize) -> usize;
pub fn fido_assert_sig_len(arg1: *const fido_assert_t, arg2: usize) -> usize;
pub fn fido_assert_user_id_len(arg1: *const fido_assert_t, arg2: usize) -> usize;
pub fn fido_assert_blob_len(arg1: *const fido_assert_t, arg2: usize) -> usize;
pub fn fido_cbor_info_aaguid_len(arg1: *const fido_cbor_info_t) -> usize;
pub fn fido_cbor_info_algorithm_count(arg1: *const fido_cbor_info_t) -> usize;
pub fn fido_cbor_info_certs_len(arg1: *const fido_cbor_info_t) -> usize;
pub fn fido_cbor_info_extensions_len(arg1: *const fido_cbor_info_t) -> usize;
pub fn fido_cbor_info_options_len(arg1: *const fido_cbor_info_t) -> usize;
pub fn fido_cbor_info_protocols_len(arg1: *const fido_cbor_info_t) -> usize;
pub fn fido_cbor_info_transports_len(arg1: *const fido_cbor_info_t) -> usize;
pub fn fido_cbor_info_versions_len(arg1: *const fido_cbor_info_t) -> usize;
pub fn fido_cred_aaguid_len(arg1: *const fido_cred_t) -> usize;
pub fn fido_cred_attstmt_len(arg1: *const fido_cred_t) -> usize;
pub fn fido_cred_authdata_len(arg1: *const fido_cred_t) -> usize;
pub fn fido_cred_authdata_raw_len(arg1: *const fido_cred_t) -> usize;
pub fn fido_cred_clientdata_hash_len(arg1: *const fido_cred_t) -> usize;
pub fn fido_cred_id_len(arg1: *const fido_cred_t) -> usize;
pub fn fido_cred_largeblob_key_len(arg1: *const fido_cred_t) -> usize;
pub fn fido_cred_pin_minlen(arg1: *const fido_cred_t) -> usize;
pub fn fido_cred_pubkey_len(arg1: *const fido_cred_t) -> usize;
pub fn fido_cred_sig_len(arg1: *const fido_cred_t) -> usize;
pub fn fido_cred_user_id_len(arg1: *const fido_cred_t) -> usize;
pub fn fido_cred_x5c_len(arg1: *const fido_cred_t) -> usize;
pub fn fido_assert_flags(arg1: *const fido_assert_t, arg2: usize) -> u8;
pub fn fido_assert_sigcount(arg1: *const fido_assert_t, arg2: usize) -> u32;
pub fn fido_cred_flags(arg1: *const fido_cred_t) -> u8;
pub fn fido_cred_sigcount(arg1: *const fido_cred_t) -> u32;
pub fn fido_dev_protocol(arg1: *const fido_dev_t) -> u8;
pub fn fido_dev_major(arg1: *const fido_dev_t) -> u8;
pub fn fido_dev_minor(arg1: *const fido_dev_t) -> u8;
pub fn fido_dev_build(arg1: *const fido_dev_t) -> u8;
pub fn fido_dev_flags(arg1: *const fido_dev_t) -> u8;
pub fn fido_dev_info_vendor(arg1: *const fido_dev_info_t) -> i16;
pub fn fido_dev_info_product(arg1: *const fido_dev_info_t) -> i16;
pub fn fido_cbor_info_fwversion(arg1: *const fido_cbor_info_t) -> u64;
pub fn fido_cbor_info_maxcredbloblen(arg1: *const fido_cbor_info_t) -> u64;
pub fn fido_cbor_info_maxcredcntlst(arg1: *const fido_cbor_info_t) -> u64;
pub fn fido_cbor_info_maxcredidlen(arg1: *const fido_cbor_info_t) -> u64;
pub fn fido_cbor_info_maxlargeblob(arg1: *const fido_cbor_info_t) -> u64;
pub fn fido_cbor_info_maxmsgsiz(arg1: *const fido_cbor_info_t) -> u64;
pub fn fido_cbor_info_maxrpid_minpinlen(arg1: *const fido_cbor_info_t) -> u64;
pub fn fido_cbor_info_minpinlen(arg1: *const fido_cbor_info_t) -> u64;
pub fn fido_cbor_info_uv_attempts(arg1: *const fido_cbor_info_t) -> u64;
pub fn fido_cbor_info_uv_modality(arg1: *const fido_cbor_info_t) -> u64;
pub fn fido_cbor_info_rk_remaining(arg1: *const fido_cbor_info_t) -> i64;
pub fn fido_dev_has_pin(arg1: *const fido_dev_t) -> bool;
pub fn fido_dev_has_uv(arg1: *const fido_dev_t) -> bool;
pub fn fido_dev_is_fido2(arg1: *const fido_dev_t) -> bool;
pub fn fido_dev_is_winhello(arg1: *const fido_dev_t) -> bool;
pub fn fido_dev_supports_credman(arg1: *const fido_dev_t) -> bool;
pub fn fido_dev_supports_cred_prot(arg1: *const fido_dev_t) -> bool;
pub fn fido_dev_supports_permissions(arg1: *const fido_dev_t) -> bool;
pub fn fido_dev_supports_pin(arg1: *const fido_dev_t) -> bool;
pub fn fido_dev_supports_uv(arg1: *const fido_dev_t) -> bool;
pub fn fido_cbor_info_new_pin_required(arg1: *const fido_cbor_info_t) -> bool;
pub fn fido_dev_largeblob_get(
arg1: *mut fido_dev_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
arg4: *mut *mut ::std::os::raw::c_uchar,
arg5: *mut usize,
) -> ::std::os::raw::c_int;
pub fn fido_dev_largeblob_set(
arg1: *mut fido_dev_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
arg4: *const ::std::os::raw::c_uchar,
arg5: usize,
arg6: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
pub fn fido_dev_largeblob_remove(
arg1: *mut fido_dev_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
arg4: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
pub fn fido_dev_largeblob_get_array(
arg1: *mut fido_dev_t,
arg2: *mut *mut ::std::os::raw::c_uchar,
arg3: *mut usize,
) -> ::std::os::raw::c_int;
pub fn fido_dev_largeblob_set_array(
arg1: *mut fido_dev_t,
arg2: *const ::std::os::raw::c_uchar,
arg3: usize,
arg4: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
pub fn rs256_pk_new() -> *mut rs256_pk_t;
pub fn rs256_pk_free(arg1: *mut *mut rs256_pk_t);
pub fn rs256_pk_to_EVP_PKEY(arg1: *const rs256_pk_t) -> *mut EVP_PKEY;
pub fn rs256_pk_from_EVP_PKEY(
arg1: *mut rs256_pk_t,
arg2: *const EVP_PKEY,
) -> ::std::os::raw::c_int;
pub fn rs256_pk_from_RSA(arg1: *mut rs256_pk_t, arg2: *const RSA) -> ::std::os::raw::c_int;
pub fn rs256_pk_from_ptr(
arg1: *mut rs256_pk_t,
arg2: *const ::std::os::raw::c_void,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn es256_pk_new() -> *mut es256_pk_t;
pub fn es256_pk_free(arg1: *mut *mut es256_pk_t);
pub fn es256_pk_to_EVP_PKEY(arg1: *const es256_pk_t) -> *mut EVP_PKEY;
pub fn es256_pk_from_EC_KEY(
arg1: *mut es256_pk_t,
arg2: *const EC_KEY,
) -> ::std::os::raw::c_int;
pub fn es256_pk_from_EVP_PKEY(
arg1: *mut es256_pk_t,
arg2: *const EVP_PKEY,
) -> ::std::os::raw::c_int;
pub fn es256_pk_from_ptr(
arg1: *mut es256_pk_t,
arg2: *const ::std::os::raw::c_void,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn es384_pk_new() -> *mut es384_pk_t;
pub fn es384_pk_free(arg1: *mut *mut es384_pk_t);
pub fn es384_pk_to_EVP_PKEY(arg1: *const es384_pk_t) -> *mut EVP_PKEY;
pub fn es384_pk_from_EC_KEY(
arg1: *mut es384_pk_t,
arg2: *const EC_KEY,
) -> ::std::os::raw::c_int;
pub fn es384_pk_from_EVP_PKEY(
arg1: *mut es384_pk_t,
arg2: *const EVP_PKEY,
) -> ::std::os::raw::c_int;
pub fn es384_pk_from_ptr(
arg1: *mut es384_pk_t,
arg2: *const ::std::os::raw::c_void,
arg3: usize,
) -> ::std::os::raw::c_int;
pub fn eddsa_pk_new() -> *mut eddsa_pk_t;
pub fn eddsa_pk_free(arg1: *mut *mut eddsa_pk_t);
pub fn eddsa_pk_to_EVP_PKEY(arg1: *const eddsa_pk_t) -> *mut EVP_PKEY;
pub fn eddsa_pk_from_EVP_PKEY(
arg1: *mut eddsa_pk_t,
arg2: *const EVP_PKEY,
) -> ::std::os::raw::c_int;
pub fn eddsa_pk_from_ptr(
arg1: *mut eddsa_pk_t,
arg2: *const ::std::os::raw::c_void,
arg3: usize,
) -> ::std::os::raw::c_int;
}

4
libfido2-sys/src/lib.rs Normal file
View File

@ -0,0 +1,4 @@
#[allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
mod ffi;
pub use ffi::*;

3
src/assert.rs Normal file
View File

@ -0,0 +1,3 @@
use libfido2_sys::*;
c_type_wrapper!(fido_assert_t, Assertion, free = fido_assert_free);

391
src/cred.rs Normal file
View File

@ -0,0 +1,391 @@
use std::{ffi::{CStr, CString}};
use libfido2_sys::*;
use num_enum::TryFromPrimitive;
use crate::{
check_initialized,
error::{check, Result},
opt_bool_to_fido_opt,
};
#[repr(i32)]
#[derive(Debug, Clone, Copy, TryFromPrimitive)]
pub enum CredProtection {
UvOptional = FIDO_CRED_PROT_UV_OPTIONAL,
UvOptionalWithID = FIDO_CRED_PROT_UV_OPTIONAL_WITH_ID,
UvRequired = FIDO_CRED_PROT_UV_REQUIRED,
}
#[repr(i32)]
#[derive(Debug, Clone, Copy, TryFromPrimitive)]
pub enum CredType {
Ecdsa256 = COSE_ES256,
Ecdsa384 = COSE_ES384,
Rsa = COSE_RS256,
Ed25519 = COSE_EDDSA,
}
c_type_wrapper!(fido_cred_t, Credential, free = fido_cred_free);
impl Credential {
pub fn new() -> Result<Self> {
check_initialized()?;
unsafe {
let ptr = fido_cred_new();
Ok(Self::from_ptr(ptr))
}
}
}
impl CredentialRef {
pub fn aaguid(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
fido_cred_aaguid_ptr(self.as_ptr()),
fido_cred_aaguid_len(self.as_ptr()),
)
}
}
pub fn attstmt(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
fido_cred_attstmt_ptr(self.as_ptr()),
fido_cred_attstmt_len(self.as_ptr()),
)
}
}
pub fn authdata(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
fido_cred_authdata_ptr(self.as_ptr()),
fido_cred_authdata_len(self.as_ptr()),
)
}
}
pub fn authdata_raw(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
fido_cred_authdata_raw_ptr(self.as_ptr()),
fido_cred_authdata_raw_len(self.as_ptr()),
)
}
}
pub fn clientdata_hash(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
fido_cred_clientdata_hash_ptr(self.as_ptr()),
fido_cred_clientdata_hash_len(self.as_ptr()),
)
}
}
pub fn display_name(&self) -> Option<&str> {
unsafe {
let ptr = fido_cred_display_name(self.as_ptr());
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_str().unwrap())
}
}
}
pub fn exclude(&mut self, cred: &[u8]) -> Result<()> {
unsafe { check(fido_cred_exclude(self.as_ptr_mut(), &cred[0], cred.len())) }
}
pub fn flags(&self) -> u8 {
unsafe { fido_cred_flags(self.as_ptr()) }
}
pub fn fmt(&self) -> Option<&str> {
unsafe {
let ptr = fido_cred_fmt(self.as_ptr());
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_str().unwrap())
}
}
}
pub fn cred_id(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
fido_cred_id_ptr(self.as_ptr()),
fido_cred_id_len(self.as_ptr()),
)
}
}
pub fn largeblob_key(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
fido_cred_largeblob_key_ptr(self.as_ptr()),
fido_cred_largeblob_key_len(self.as_ptr()),
)
}
}
pub fn pin_minlen(&self) -> Option<usize> {
unsafe {
let minlen = fido_cred_pin_minlen(self.as_ptr());
if minlen == 0 {
None
} else {
Some(minlen)
}
}
}
pub fn prot(&self) -> Option<CredProtection> {
unsafe {
let prot = fido_cred_prot(self.as_ptr());
if prot == 0 {
None
} else {
Some(CredProtection::try_from(prot).unwrap())
}
}
}
pub fn pubkey(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
fido_cred_pubkey_ptr(self.as_ptr()),
fido_cred_pubkey_len(self.as_ptr()),
)
}
}
pub fn rp_id(&self) -> Option<&str> {
unsafe {
let ptr = fido_cred_rp_id(self.as_ptr());
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_str().unwrap())
}
}
}
pub fn rp_name(&self) -> Option<&str> {
unsafe {
let ptr = fido_cred_rp_name(self.as_ptr());
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_str().unwrap())
}
}
}
pub fn set_attstmt(&mut self, data: &[u8]) -> Result<()> {
unsafe {
check(fido_cred_set_attstmt(
self.as_ptr_mut(),
&data[0],
data.len(),
))
}
}
pub fn set_authdata(&mut self, data: &[u8]) -> Result<()> {
unsafe {
check(fido_cred_set_authdata(
self.as_ptr_mut(),
&data[0],
data.len(),
))
}
}
pub fn set_authdata_raw(&mut self, data: &[u8]) -> Result<()> {
unsafe {
check(fido_cred_set_authdata_raw(
self.as_ptr_mut(),
&data[0],
data.len(),
))
}
}
pub fn set_blob(&mut self, blob: &[u8]) -> Result<()> {
unsafe { check(fido_cred_set_blob(self.as_ptr_mut(), &blob[0], blob.len())) }
}
pub fn set_clientdata(&mut self, data: &[u8]) -> Result<()> {
unsafe {
check(fido_cred_set_clientdata(
self.as_ptr_mut(),
&data[0],
data.len(),
))
}
}
pub fn set_clientdata_hash(&mut self, hash: &[u8]) -> Result<()> {
unsafe {
check(fido_cred_set_clientdata_hash(
self.as_ptr_mut(),
&hash[0],
hash.len(),
))
}
}
pub fn set_extensions(&mut self, flags: i32) -> Result<()> {
unsafe { check(fido_cred_set_extensions(self.as_ptr_mut(), flags)) }
}
pub fn set_fmt(&mut self, fmt: impl AsRef<str>) -> Result<()> {
let fmt = CString::new(fmt.as_ref()).unwrap();
unsafe { check(fido_cred_set_fmt(self.as_ptr_mut(), fmt.as_ptr())) }
}
pub fn set_id(&mut self, id: &[u8]) -> Result<()> {
unsafe { check(fido_cred_set_id(self.as_ptr_mut(), &id[0], id.len())) }
}
pub fn set_pin_minlen(&mut self, len: usize) -> Result<()> {
unsafe { check(fido_cred_set_pin_minlen(self.as_ptr_mut(), len)) }
}
pub fn set_prot(&mut self, prot: CredProtection) -> Result<()> {
unsafe { check(fido_cred_set_prot(self.as_ptr_mut(), prot as i32)) }
}
pub fn set_rk(&mut self, rk: Option<bool>) -> Result<()> {
unsafe {
check(fido_cred_set_rk(
self.as_ptr_mut(),
opt_bool_to_fido_opt(rk),
))
}
}
pub fn set_rp(&mut self, id: impl AsRef<str>, name: impl AsRef<str>) -> Result<()> {
let id = CString::new(id.as_ref()).unwrap();
let name = CString::new(name.as_ref()).unwrap();
unsafe {
check(fido_cred_set_rp(
self.as_ptr_mut(),
id.as_ptr(),
name.as_ptr(),
))
}
}
pub fn set_sig(&mut self, sig: &[u8]) -> Result<()> {
unsafe { check(fido_cred_set_sig(self.as_ptr_mut(), &sig[0], sig.len())) }
}
pub fn set_type(&mut self, typ: CredType) -> Result<()> {
unsafe { check(fido_cred_set_type(self.as_ptr_mut(), typ as i32)) }
}
pub fn set_user(
&mut self,
id: impl AsRef<[u8]>,
name: impl AsRef<str>,
display_name: Option<&str>,
icon: Option<&str>,
) -> Result<()> {
let id = id.as_ref();
let name = CString::new(name.as_ref()).unwrap();
let display_name = display_name
.map(|x| CString::new(x).unwrap())
.unwrap_or_default();
let icon = icon.map(|x| CString::new(x).unwrap()).unwrap_or_default();
unsafe {
check(fido_cred_set_user(
self.as_ptr_mut(),
&id[0],
id.len(),
name.as_ptr(),
display_name.as_ptr(),
icon.as_ptr(),
))
}
}
pub fn set_uv(&mut self, uv: Option<bool>) -> Result<()> {
unsafe {
check(fido_cred_set_uv(
self.as_ptr_mut(),
opt_bool_to_fido_opt(uv),
))
}
}
pub fn set_x509(&mut self, x509: &[u8]) -> Result<()> {
unsafe { check(fido_cred_set_x509(self.as_ptr_mut(), &x509[0], x509.len())) }
}
pub fn sig(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
fido_cred_sig_ptr(self.as_ptr()),
fido_cred_sig_len(self.as_ptr()),
)
}
}
pub fn sigcount(&self) -> u32 {
unsafe { fido_cred_sigcount(self.as_ptr()) }
}
pub fn get_type(&self) -> Option<CredType> {
unsafe {
let typ = fido_cred_type(self.as_ptr());
if typ == 0 {
None
} else {
Some(CredType::try_from(typ).unwrap())
}
}
}
pub fn user_id(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
fido_cred_user_id_ptr(self.as_ptr()),
fido_cred_user_id_len(self.as_ptr()),
)
}
}
pub fn user_name(&self) -> Option<&str> {
unsafe {
let ptr = fido_cred_user_name(self.as_ptr());
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_str().unwrap())
}
}
}
pub fn verify(&self) -> Result<()> {
unsafe { check(fido_cred_verify(self.as_ptr())) }
}
pub fn verify_self(&self) -> Result<()> {
unsafe { check(fido_cred_verify_self(self.as_ptr())) }
}
pub fn x5c(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
fido_cred_x5c_ptr(self.as_ptr()),
fido_cred_x5c_len(self.as_ptr()),
)
}
}
}

270
src/device.rs Normal file
View File

@ -0,0 +1,270 @@
use std::{
ffi::{CStr, CString},
fmt::Debug,
ops::Index,
ptr::{self, NonNull},
};
use libfido2_sys::*;
use crate::{
assert::Assertion,
check_initialized,
cred::CredentialRef,
error::{check, Result},
};
#[derive(Clone)]
pub struct DeviceList {
ptr: NonNull<fido_dev_info_t>,
len: usize,
}
impl Debug for DeviceList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut helper = f.debug_list();
for i in 0..self.len {
helper.entry(&self[i]);
}
helper.finish()
}
}
impl DeviceList {
pub fn get_list(max: usize) -> Result<Self> {
check_initialized()?;
let mut len = 0;
unsafe {
let ptr = fido_dev_info_new(max);
fido_dev_info_manifest(ptr, max, &mut len);
Ok(DeviceList {
ptr: NonNull::new_unchecked(ptr),
len,
})
}
}
pub fn len(&self) -> usize {
self.len
}
}
impl Index<usize> for DeviceList {
type Output = DeviceInfoRef;
fn index(&self, index: usize) -> &Self::Output {
assert!(index < self.len);
unsafe { &*(fido_dev_info_ptr(self.ptr.as_ptr(), index).cast()) }
}
}
impl Drop for DeviceList {
fn drop(&mut self) {
unsafe {
fido_dev_info_free(&mut self.ptr.as_ptr(), self.len);
}
}
}
c_type_wrapper_ref!(fido_dev_info_t, DeviceInfo);
impl Debug for DeviceInfoRef {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut helper = f.debug_struct("DeviceInfoRef");
helper.field("vendor_id", &self.vendor_id());
helper.field("product_id", &self.product_id());
helper.field("manufacturer", &self.manufacturer());
helper.field("product", &self.product());
helper.field("path", &self.path());
helper.finish()
}
}
impl DeviceInfoRef {
pub fn vendor_id(&self) -> i16 {
unsafe { fido_dev_info_vendor(self.as_ptr()) }
}
pub fn product_id(&self) -> i16 {
unsafe { fido_dev_info_product(self.as_ptr()) }
}
pub fn manufacturer(&self) -> &str {
unsafe {
CStr::from_ptr(fido_dev_info_manufacturer_string(self.as_ptr()))
.to_str()
.unwrap()
}
}
pub fn product(&self) -> &str {
unsafe {
CStr::from_ptr(fido_dev_info_product_string(self.as_ptr()))
.to_str()
.unwrap()
}
}
pub fn path(&self) -> &str {
unsafe {
CStr::from_ptr(fido_dev_info_path(self.as_ptr()))
.to_str()
.unwrap()
}
}
pub fn open(&self) -> Device {
unsafe {
let dev_ptr = fido_dev_new_with_info(self.as_ptr());
fido_dev_open_with_info(dev_ptr);
Device {
ptr: NonNull::new_unchecked(dev_ptr),
}
}
}
}
c_type_wrapper!(fido_dev_t, Device);
impl Drop for Device {
fn drop(&mut self) {
unsafe {
fido_dev_close(self.ptr.as_ptr());
fido_dev_free(&mut self.ptr.as_ptr());
}
}
}
impl Device {
pub fn open(path: impl AsRef<str>) -> Result<Self> {
check_initialized()?;
let path = CString::new(path.as_ref()).unwrap();
unsafe {
let ptr = fido_dev_new();
check(fido_dev_open(ptr, path.as_ptr()))?;
Ok(Self::from_ptr(ptr))
}
}
}
impl DeviceRef {
pub fn force_fido2(&mut self) {
unsafe { fido_dev_force_fido2(self.as_ptr_mut()) }
}
pub fn force_u2f(&mut self) {
unsafe { fido_dev_force_u2f(self.as_ptr_mut()) }
}
pub fn is_fido2(&self) -> bool {
unsafe { fido_dev_is_fido2(self.as_ptr()) }
}
pub fn is_winhello(&self) -> bool {
unsafe { fido_dev_is_winhello(self.as_ptr()) }
}
pub fn supports_cred_prot(&self) -> bool {
unsafe { fido_dev_supports_cred_prot(self.as_ptr()) }
}
pub fn supports_credman(&self) -> bool {
unsafe { fido_dev_supports_credman(self.as_ptr()) }
}
pub fn supports_permissions(&self) -> bool {
unsafe { fido_dev_supports_permissions(self.as_ptr()) }
}
pub fn supports_pin(&self) -> bool {
unsafe { fido_dev_supports_pin(self.as_ptr()) }
}
pub fn supports_uv(&self) -> bool {
unsafe { fido_dev_supports_uv(self.as_ptr()) }
}
pub fn has_pin(&self) -> bool {
unsafe { fido_dev_has_pin(self.as_ptr()) }
}
pub fn has_uv(&self) -> bool {
unsafe { fido_dev_has_uv(self.as_ptr()) }
}
pub fn protocol(&self) -> u8 {
unsafe { fido_dev_protocol(self.as_ptr()) }
}
pub fn build(&self) -> u8 {
unsafe { fido_dev_build(self.as_ptr()) }
}
pub fn flags(&self) -> u8 {
unsafe { fido_dev_flags(self.as_ptr()) }
}
pub fn major(&self) -> u8 {
unsafe { fido_dev_major(self.as_ptr()) }
}
pub fn minor(&self) -> u8 {
unsafe { fido_dev_minor(self.as_ptr()) }
}
pub fn get_assert(&mut self, assert: &mut Assertion, pin: Option<&str>) -> Result<()> {
let pin = pin.map(|x| CString::new(x).unwrap()).unwrap_or_default();
unsafe {
check(fido_dev_get_assert(
self.as_ptr_mut(),
assert.as_ptr_mut(),
pin.as_ptr(),
))
}
}
//TODO: CBOR info
pub fn set_pin(&mut self, pin: impl AsRef<str>, oldpin: Option<&str>) -> Result<()> {
let pin = CString::new(pin.as_ref()).unwrap();
let oldpin = oldpin.map_or(ptr::null(), |str| str.as_ptr()).cast();
unsafe { check(fido_dev_set_pin(self.as_ptr_mut(), pin.as_ptr(), oldpin)) }
}
pub fn get_retry_count(&mut self) -> Result<u32> {
let mut retries = 0;
unsafe {
check(fido_dev_get_retry_count(self.as_ptr_mut(), &mut retries))?;
};
Ok(retries as u32)
}
pub fn get_uv_retry_count(&mut self) -> Result<u32> {
let mut retries = 0;
unsafe {
check(fido_dev_get_uv_retry_count(self.as_ptr_mut(), &mut retries))?;
};
Ok(retries as u32)
}
pub fn reset(&mut self) -> Result<()> {
unsafe { check(fido_dev_reset(self.as_ptr_mut())) }
}
//TODO: largeBlobs
pub fn make_cred(&mut self, cred: &mut CredentialRef, pin: Option<&str>) -> Result<()> {
let pin = pin.map(|x| CString::new(x).unwrap()).unwrap_or_default();
unsafe {
check(fido_dev_make_cred(
self.as_ptr_mut(),
cred.as_ptr_mut(),
pin.as_ptr(),
))
}
}
}

96
src/error.rs Normal file
View File

@ -0,0 +1,96 @@
use std::{ffi::CStr, fmt::Display};
use libfido2_sys::fido_strerr;
use num_enum::TryFromPrimitive;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Clone, Copy, Debug)]
pub enum Error {
#[error("FIDO library not initialized")]
NotInitialized,
#[error("libfido2: {0}")]
Libfido2(#[from] Libfido2Error),
}
#[repr(i32)]
#[derive(Error, Clone, Copy, Debug, TryFromPrimitive)]
pub enum Libfido2Error {
InvalidCommand = 0x01,
InvalidParameter = 0x02,
InvalidLength = 0x03,
InvalidSeq = 0x04,
Timeout = 0x05,
ChannelBusy = 0x06,
LockRequired = 0x0a,
InvalidChannel = 0x0b,
CborUnexpectedType = 0x11,
InvalidCbor = 0x12,
MissingParameter = 0x14,
LimitExceeded = 0x15,
UnsupportedExtension = 0x16,
FpDatabaseFull = 0x17,
LargeblobStorageFull = 0x18,
CredentialExcluded = 0x19,
Processing = 0x21,
InvalidCredential = 0x22,
UserActionPending = 0x23,
OperationPending = 0x24,
NoOperations = 0x25,
UnsupportedAlgorithm = 0x26,
OperationDenied = 0x27,
KeyStoreFull = 0x28,
NotBusy = 0x29,
NoOperationPending = 0x2a,
UnsupportedOption = 0x2b,
InvalidOption = 0x2c,
KeepaliveCancel = 0x2d,
NoCredentials = 0x2e,
UserActionTimeout = 0x2f,
NotAllowed = 0x30,
PinInvalid = 0x31,
PinBlocked = 0x32,
PinAuthInvalid = 0x33,
PinAuthBlocked = 0x34,
PinNotSet = 0x35,
PinRequired = 0x36,
PinPolicyViolation = 0x37,
PinTokenExpired = 0x38,
RequestTooLarge = 0x39,
ActionTimeout = 0x3a,
UpRequired = 0x3b,
UvBlocked = 0x3c,
UvInvalid = 0x3f,
UnauthorizedPerm = 0x40,
ErrOther = 0x7f,
SpecLast = 0xdf,
Tx = -1,
Rx = -2,
RxNotCbor = -3,
RxInvalidCbor = -4,
InvalidParam = -5,
InvalidSig = -6,
InvalidArgument = -7,
UserPresenceRequired = -8,
Internal = -9,
Notfound = -10,
Compress = -11,
}
impl Display for Libfido2Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let err_str = unsafe { CStr::from_ptr(fido_strerr(*self as i32)) }
.to_str()
.unwrap();
f.write_str(err_str)
}
}
pub(crate) fn check(err_code: i32) -> Result<()> {
if err_code == 0 {
Ok(())
} else {
Err(Libfido2Error::try_from(err_code).unwrap().into())
}
}

50
src/lib.rs Normal file
View File

@ -0,0 +1,50 @@
use std::sync::atomic::{AtomicBool, Ordering};
use libfido2_sys::{
fido_opt_t_FIDO_OPT_FALSE, fido_opt_t_FIDO_OPT_OMIT, fido_opt_t_FIDO_OPT_TRUE, FIDO_DEBUG,
};
#[macro_use]
mod macros;
pub mod assert;
pub mod cred;
pub mod device;
pub mod error;
use error::{Error, Result};
static FIDO_INITIALIZED: AtomicBool = AtomicBool::new(false);
pub fn fido_init(debug: bool) {
static FIDO_INITIALIZE_STARTED: AtomicBool = AtomicBool::new(false);
if FIDO_INITIALIZE_STARTED
.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
.is_err()
{
return;
}
if debug {
unsafe { libfido2_sys::fido_init(FIDO_DEBUG) };
} else {
unsafe { libfido2_sys::fido_init(0) };
}
FIDO_INITIALIZED.store(true, Ordering::Relaxed);
check_initialized().unwrap();
}
fn check_initialized() -> Result<()> {
if !FIDO_INITIALIZED.load(Ordering::Relaxed) {
Err(Error::NotInitialized)
} else {
Ok(())
}
}
fn opt_bool_to_fido_opt(opt: Option<bool>) -> i32 {
match opt {
Some(true) => fido_opt_t_FIDO_OPT_TRUE,
Some(false) => fido_opt_t_FIDO_OPT_FALSE,
None => fido_opt_t_FIDO_OPT_OMIT,
}
}

84
src/macros.rs Normal file
View File

@ -0,0 +1,84 @@
macro_rules! c_type_wrapper {
($c: ident, $t: ident, free = $f: ident) => {
c_type_wrapper!($c, $t);
impl ::core::ops::Drop for $t {
fn drop(&mut self) {
unsafe {
$f(&mut self.ptr.as_ptr())
}
}
}
};
($c: ident, $t: ident) => {
::paste::paste! {
pub struct $t {
ptr: ::core::ptr::NonNull<$c>,
}
impl $t {
#[allow(unused)]
unsafe fn from_ptr<'a>(ptr: *mut $c) -> Self {
unsafe {
$t {
ptr: ::core::ptr::NonNull::new_unchecked(ptr),
}
}
}
#[allow(unused)]
pub(crate) fn as_ptr(&self) -> *const $c {
self.ptr.as_ptr()
}
#[allow(unused)]
pub(crate) fn as_ptr_mut(&mut self) -> *mut $c {
self.ptr.as_ptr()
}
}
impl ::core::ops::Deref for $t {
type Target = [<$t Ref>];
fn deref(&self) -> &[<$t Ref>] {
unsafe { &*(self.ptr.as_ptr() as *const [<$t Ref>]) }
}
}
impl ::core::ops::DerefMut for $t {
fn deref_mut(&mut self) -> &mut [<$t Ref>]{
unsafe { &mut *(self.ptr.as_ptr() as *mut [<$t Ref>]) }
}
}
c_type_wrapper_ref!($c, $t);
}
}
}
macro_rules! c_type_wrapper_ref {
($c: ident, $t: ident) => {
::paste::paste! {
pub struct [<$t Ref>](::core::marker::PhantomData<::core::cell::UnsafeCell<*mut ()>>);
impl [<$t Ref>] {
#[allow(unused)]
unsafe fn from_ptr<'a>(ptr: *const $c) -> &'a Self {
unsafe { &*(ptr as *const _) }
}
#[allow(unused)]
unsafe fn from_ptr_mut<'a>(ptr: *mut $c) -> &'a mut Self {
unsafe { &mut *(ptr as *mut _)}
}
#[allow(unused)]
pub(crate) fn as_ptr(&self) -> *const $c {
self as *const [<$t Ref>] as *const $c
}
#[allow(unused)]
pub(crate) fn as_ptr_mut(&mut self) -> *mut $c {
self as *mut [<$t Ref>] as *mut $c
}
}
}
}
}