Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PKCS 11 ProviderID enumeration variant #8

Merged
merged 1 commit into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "parsec-interface"
version = "0.2.1"
authors = ["Ionut Mihalcea <[email protected]>",
version = "0.3.0"
authors = ["Paul Howard <[email protected]>",
"Ionut Mihalcea <[email protected]>",
"Hugues de Valon <[email protected]>"]
edition = "2018"

Expand Down
35 changes: 12 additions & 23 deletions src/operations/key_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ use num_derive::FromPrimitive;
/// Each variant of the enum contains a main algorithm type (which is required for
/// that variant), as well as configuration fields as allowed by each algorithm in
/// part.
#[derive(Debug, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug, Clone, PartialEq)]
pub enum AlgorithmInner {
Cipher(CipherAlgorithm),
AsymmetricEncryption(AsymmetricEncryptionAlgorithm, Option<HashAlgorithm>),
Expand All @@ -39,7 +38,7 @@ pub enum AlgorithmInner {

/// Wrapper around `AlgorithmInner`, used to statically ensure that any algorithm used
/// in `KeyAttributes` is a valid combination of algorithms and options.
#[derive(Clone)]
#[derive(Clone, PartialEq)]
pub struct Algorithm(AlgorithmInner);

impl Algorithm {
Expand Down Expand Up @@ -111,8 +110,7 @@ pub struct KeyAttributes {
}

/// Enumeration of key types supported.
#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(FromPrimitive, Copy, Clone, Debug, PartialEq)]
#[repr(i32)]
pub enum KeyType {
HmacKey = 0,
Expand All @@ -133,8 +131,7 @@ pub enum KeyType {
///
/// Should only be used for keys with `key_type` either `EccPublicKey`
/// or `EccKeypair`.
#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(FromPrimitive, Copy, Clone, Debug, PartialEq)]
#[repr(i32)]
pub enum EccCurve {
Sect163k1 = 1,
Expand Down Expand Up @@ -173,8 +170,7 @@ pub enum EccCurve {
///
/// Includes both specific algorithms (ARC4) and modes of operation
/// for algorithms defined through the key type (e.g. `AesKey`).
#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(FromPrimitive, Copy, Clone, Debug, PartialEq)]
#[repr(i32)]
pub enum CipherAlgorithm {
Arc4 = 0,
Expand All @@ -187,17 +183,15 @@ pub enum CipherAlgorithm {
}

/// Enumeration of asymmetric encryption algorithms supported.
#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(FromPrimitive, Copy, Clone, Debug, PartialEq)]
#[repr(i32)]
pub enum AsymmetricEncryptionAlgorithm {
RsaPkcs1v15Crypt = 0,
RsaOaep = 1,
}

/// Enumeration of message authentication code algorithms supported.
#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(FromPrimitive, Copy, Clone, Debug, PartialEq)]
#[repr(i32)]
pub enum MacAlgorithm {
Hmac = 0,
Expand All @@ -208,17 +202,15 @@ pub enum MacAlgorithm {

/// Enumeration of authenticated encryption with additional data algorithms
/// supported.
#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(FromPrimitive, Copy, Clone, Debug, PartialEq)]
#[repr(i32)]
pub enum AeadAlgorithm {
Ccm = 0,
Gcm = 1,
}

/// Enumeration of asymmetric signing algorithms supported.
#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(FromPrimitive, Copy, Clone, Debug, PartialEq)]
#[repr(i32)]
pub enum SignAlgorithm {
RsaPkcs1v15Sign = 0,
Expand All @@ -230,17 +222,15 @@ pub enum SignAlgorithm {
}

/// Enumeration of key agreement algorithms supported.
#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(FromPrimitive, Copy, Clone, Debug, PartialEq)]
#[repr(i32)]
pub enum KeyAgreementAlgorithm {
Ffdh = 0,
Ecdh = 1,
}

/// Enumeration of hash algorithms supported.
#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(FromPrimitive, Copy, Clone, Debug, PartialEq)]
#[repr(i32)]
pub enum HashAlgorithm {
Md2 = 1,
Expand All @@ -261,8 +251,7 @@ pub enum HashAlgorithm {
}

/// Enumeration of key derivation functions supported.
#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(FromPrimitive, Copy, Clone, Debug, PartialEq)]
#[repr(i32)]
pub enum KeyDerivationFunction {
Hkdf = 0,
Expand Down
2 changes: 2 additions & 0 deletions src/requests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub enum ProviderID {
CoreProvider = 0,
/// Provider using Mbed Crypto software library.
MbedProvider = 1,
/// Provider using a PKCS 11 compatible library.
Pkcs11Provider = 2,
}

impl std::fmt::Display for ProviderID {
Expand Down