Skip to content

Commit

Permalink
Add missing traits necessary for cliclack
Browse files Browse the repository at this point in the history
  • Loading branch information
aveenismail committed Oct 17, 2023
1 parent bd5ece8 commit 9f49402
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ regex = "0.2.2"
rustc-serialize = "0.3.24"
strum = "0.24"
strum_macros = "0.24"
serde = { version = "1.0.164", features = ["derive"] }

[dev-dependencies]
base64 = "0.7.0"
Expand Down
28 changes: 15 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ extern crate log;
extern crate regex;
extern crate rustc_serialize;

extern crate serde;

use std::ffi::c_char;
use lyh::{yh_algorithm, yh_capabilities, yh_connector, yh_rc, yh_session};

Expand Down Expand Up @@ -311,7 +313,7 @@ impl Session {
id: u16,
label: &str,
domains: &[ObjectDomain],
object_capabilities: &[ObjectCapability],
capabilities: &[ObjectCapability],
delegated_capabilities: &[ObjectCapability],
password: &[u8],
) -> Result<u16, Error> {
Expand All @@ -325,7 +327,7 @@ impl Session {
&mut real_id,
c_str.as_ptr(),
ObjectDomain::primitive_from_slice(domains),
&ObjectCapability::primitive_from_slice(object_capabilities),
&ObjectCapability::primitive_from_slice(capabilities),
&ObjectCapability::primitive_from_slice(delegated_capabilities),
password.as_ptr(),
password.len(),
Expand All @@ -342,7 +344,7 @@ impl Session {
id: u16,
label: &str,
domains: &[ObjectDomain],
object_capabilities: &[ObjectCapability],
capabilities: &[ObjectCapability],
algorithm: ObjectAlgorithm,
delegated_capabilities: &[ObjectCapability],
) -> Result<u16, Error> {
Expand All @@ -356,7 +358,7 @@ impl Session {
&mut real_id,
c_str.as_ptr(),
ObjectDomain::primitive_from_slice(domains),
&ObjectCapability::primitive_from_slice(object_capabilities),
&ObjectCapability::primitive_from_slice(capabilities),
algorithm.into(),
&ObjectCapability::primitive_from_slice(delegated_capabilities),
)
Expand All @@ -374,7 +376,7 @@ impl Session {
id: u16,
label: &str,
domains: &[ObjectDomain],
object_capabilities: &[ObjectCapability],
capabilities: &[ObjectCapability],
algorithm: ObjectAlgorithm,
delegated_capabilities: &[ObjectCapability],
wrapkey: &[u8],
Expand All @@ -389,7 +391,7 @@ impl Session {
&mut real_id,
c_str.as_ptr(),
ObjectDomain::primitive_from_slice(domains),
&ObjectCapability::primitive_from_slice(object_capabilities),
&ObjectCapability::primitive_from_slice(capabilities),
algorithm.into(),
&ObjectCapability::primitive_from_slice(delegated_capabilities),
wrapkey.as_ptr(),
Expand All @@ -409,7 +411,7 @@ impl Session {
id: u16,
label: &str,
domains: &[ObjectDomain],
object_capabilities: &[ObjectCapability],
capabilities: &[ObjectCapability],
algorithm: ObjectAlgorithm,
p: &[u8],
q: &[u8],
Expand All @@ -424,7 +426,7 @@ impl Session {
&mut real_id,
c_str.as_ptr(),
ObjectDomain::primitive_from_slice(domains),
&ObjectCapability::primitive_from_slice(object_capabilities),
&ObjectCapability::primitive_from_slice(capabilities),
algorithm.into(),
p.as_ptr(),
q.as_ptr(),
Expand All @@ -442,7 +444,7 @@ impl Session {
id: u16,
label: &str,
domains: &[ObjectDomain],
object_capabilities: &[ObjectCapability],
capabilities: &[ObjectCapability],
algorithm: ObjectAlgorithm,
s: &[u8],
) -> Result<u16, Error> {
Expand All @@ -456,7 +458,7 @@ impl Session {
&mut real_id,
c_str.as_ptr(),
ObjectDomain::primitive_from_slice(domains),
&ObjectCapability::primitive_from_slice(object_capabilities),
&ObjectCapability::primitive_from_slice(capabilities),
algorithm.into(),
s.as_ptr(),
)
Expand All @@ -473,7 +475,7 @@ impl Session {
id: u16,
label: &str,
domains: &[ObjectDomain],
object_capabilities: &[ObjectCapability],
capabilities: &[ObjectCapability],
k: &[u8],
) -> Result<u16, Error> {
let mut real_id = id;
Expand All @@ -486,7 +488,7 @@ impl Session {
&mut real_id,
c_str.as_ptr(),
ObjectDomain::primitive_from_slice(domains),
&ObjectCapability::primitive_from_slice(object_capabilities),
&ObjectCapability::primitive_from_slice(capabilities),
yh_algorithm::YH_ALGO_EC_ED25519,
k.as_ptr(),
)
Expand All @@ -503,12 +505,12 @@ impl Session {
id: u16,
label: &str,
domains: &[ObjectDomain],
capabilities: &[ObjectCapability],
cert: &[u8],
) -> Result<u16, Error> {
let mut real_id = id;

let c_str = ::std::ffi::CString::new(label).unwrap();
let capabilities:[ObjectCapability; 0] = [];

let res = unsafe {
lyh::yh_util_import_opaque(
Expand Down
20 changes: 13 additions & 7 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ use std::fmt::Display;

use Session;

#[derive(Debug, Clone, Copy, PartialEq)]
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
/// Object types
pub enum ObjectType {
/// Opaque object
Opaque,
/// Authentication key
#[default]
AuthenticationKey,
/// Asymmetric key
AsymmetricKey,
Expand All @@ -51,7 +54,7 @@ pub enum ObjectType {
Any,
}

#[derive(Clone, Copy, PartialEq, Eq, std::hash::Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Default, std::hash::Hash, Serialize, Deserialize)]
/// Object capabilities
pub enum ObjectCapability {
/// Get opaque object
Expand Down Expand Up @@ -87,6 +90,7 @@ pub enum ObjectCapability {
/// Generate a wrap key
GenerateWrapKey,
/// Object is exportable under wrap
#[default]
ExportableUnderWrap,
/// Set option
SetOption,
Expand Down Expand Up @@ -148,7 +152,7 @@ pub enum ObjectCapability {
DeleteOtpAeadKey,
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// Object domains
pub enum ObjectDomain {
/// Domain one
Expand Down Expand Up @@ -185,7 +189,7 @@ pub enum ObjectDomain {
Sixteen,
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
/// Object algorithms
pub enum ObjectAlgorithm {
/// RSA PKCS1v1.5 with SHA1
Expand All @@ -205,6 +209,7 @@ pub enum ObjectAlgorithm {
/// RSA PSS with SHA512
RsaPssSha512,
/// RSA 2048
#[default]
Rsa2048,
/// RSA 3072
Rsa3072,
Expand Down Expand Up @@ -288,10 +293,11 @@ pub enum ObjectAlgorithm {
ANY,
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
/// Object origin
pub enum ObjectOrigin {
/// Generate object
#[default]
Generated,
/// Imported object
Imported,
Expand All @@ -301,7 +307,7 @@ pub enum ObjectOrigin {
WrappedImported,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
/// Object descriptor
pub struct ObjectDescriptor {
/// Ccapabilities
Expand All @@ -326,7 +332,7 @@ pub struct ObjectDescriptor {
pub delegated_capabilities: Option<Vec<ObjectCapability>>,
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
/// Object Handle
pub struct ObjectHandle {
/// Type
Expand Down

0 comments on commit 9f49402

Please sign in to comment.