Skip to content

Commit d3288df

Browse files
authored
Merge pull request #5 from hug-dev/remove-lifetimes
Remove references to key lifetime
2 parents 0f884d3 + 530aa98 commit d3288df

13 files changed

+9
-98
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::process::{Command, Output};
1919

2020
const PROTO_FOLDER: &str = "target/parsec-operations/protobuf";
2121
const PROTO_OUT_DIR: &str = "src/operations_protobuf/generated_ops";
22-
const PARSEC_OPERATIONS_VERSION: &str = "0.1.0";
22+
const PARSEC_OPERATIONS_VERSION: &str = "0.2.0";
2323

2424
// TODO: handle OsStrings more carefully, as .into_string() might fail
2525

src/operations/asym_sign.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
use super::key_attributes::KeyLifetime;
1615

1716
/// Native object for asymmetric sign operations.
1817
///
19-
/// `key_name` and `key_lifetime` define which key should be used for the signing operation.
18+
/// `key_name` defines which key should be used for the signing operation.
2019
/// The `hash` value must either be a short message (length dependend on the size of
2120
/// the key), or the result of a hashing operation. Thus, if a hash-and-sign is
2221
/// required, the hash must be computed before this operation is called. The length
@@ -27,7 +26,6 @@ use super::key_attributes::KeyLifetime;
2726
#[derive(Debug)]
2827
pub struct OpAsymSign {
2928
pub key_name: String,
30-
pub key_lifetime: KeyLifetime,
3129
pub hash: Vec<u8>,
3230
}
3331

src/operations/asym_verify.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@
1212
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
use super::key_attributes::KeyLifetime;
1615

1716
/// Native object for asymmetric verification of signatures.
1817
///
19-
/// `key_name` and `key_lifetime` specify the key to be used for verification.
18+
/// `key_name` specifies the key to be used for verification.
2019
/// The `hash` contains a short message or hash value as described for the
2120
/// asymmetric signing operation.
2221
/// `signature` contains the bytes of the signature which requires validation and must
2322
/// follow any format requirements imposed by the provider.
2423
#[derive(Debug)]
2524
pub struct OpAsymVerify {
2625
pub key_name: String,
27-
pub key_lifetime: KeyLifetime,
2826
pub hash: Vec<u8>,
2927
pub signature: Vec<u8>,
3028
}

src/operations/destroy_key.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
use super::key_attributes::KeyLifetime;
1615

1716
/// Native object for cryptographic key destruction.
1817
///
19-
/// `key_name` and `key_lifetime` identify the key to be destroyed.
18+
/// `key_name` identifies the key to be destroyed.
2019
#[derive(Debug, Clone)]
2120
pub struct OpDestroyKey {
2221
pub key_name: String,
23-
pub key_lifetime: KeyLifetime,
2422
}
2523

2624
/// Native object for result of cryptographic key destruction.

src/operations/export_public_key.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
use super::key_attributes::KeyLifetime;
1615

1716
/// Native object for public key exporting operation.
1817
///
19-
/// `key_name` and `key_lifetime` identify the key for which the public
18+
/// `key_name` identifies the key for which the public
2019
/// part will be exported. The specified key must be an asymmetric keypair.
2120
pub struct OpExportPublicKey {
2221
pub key_name: String,
23-
pub key_lifetime: KeyLifetime,
2422
}
2523

2624
/// Native object for result of public key export operation.

src/operations/key_attributes.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ impl Algorithm {
9898
/// a cryptographic key.
9999
#[derive(Clone)]
100100
pub struct KeyAttributes {
101-
pub key_lifetime: KeyLifetime,
102101
pub key_type: KeyType,
103102
pub ecc_curve: Option<EccCurve>,
104103
pub algorithm: Algorithm,
@@ -111,14 +110,6 @@ pub struct KeyAttributes {
111110
pub permit_derive: bool,
112111
}
113112

114-
#[derive(FromPrimitive, Copy, Clone, Debug)]
115-
#[cfg_attr(test, derive(PartialEq))]
116-
#[repr(i32)]
117-
pub enum KeyLifetime {
118-
Volatile = 0,
119-
Persistent = 1,
120-
}
121-
122113
/// Enumeration of key types supported.
123114
#[derive(FromPrimitive, Copy, Clone, Debug)]
124115
#[cfg_attr(test, derive(PartialEq))]

src/operations_protobuf/convert_asym_sign.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use super::generated_ops::asym_sign::{OpAsymmetricSignProto, ResultAsymmetricSignProto};
1616
use crate::operations::{OpAsymSign, ResultAsymSign};
1717
use crate::requests::ResponseStatus;
18-
use num::FromPrimitive;
1918
use std::convert::TryFrom;
2019

2120
impl TryFrom<OpAsymmetricSignProto> for OpAsymSign {
@@ -24,8 +23,6 @@ impl TryFrom<OpAsymmetricSignProto> for OpAsymSign {
2423
fn try_from(proto_op: OpAsymmetricSignProto) -> Result<Self, Self::Error> {
2524
Ok(OpAsymSign {
2625
key_name: proto_op.key_name,
27-
key_lifetime: FromPrimitive::from_i32(proto_op.key_lifetime)
28-
.expect("Failed to convert key lifetime"),
2926
hash: proto_op.hash,
3027
})
3128
}
@@ -37,7 +34,6 @@ impl TryFrom<OpAsymSign> for OpAsymmetricSignProto {
3734
fn try_from(op: OpAsymSign) -> Result<Self, Self::Error> {
3835
Ok(OpAsymmetricSignProto {
3936
key_name: op.key_name,
40-
key_lifetime: op.key_lifetime as i32,
4137
hash: op.hash,
4238
})
4339
}
@@ -69,9 +65,7 @@ mod test {
6965
OpAsymmetricSignProto, ResultAsymmetricSignProto,
7066
};
7167
use super::super::{Convert, ProtobufConverter};
72-
use crate::operations::{
73-
key_attributes, NativeOperation, NativeResult, OpAsymSign, ResultAsymSign,
74-
};
68+
use crate::operations::{NativeOperation, NativeResult, OpAsymSign, ResultAsymSign};
7569
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode};
7670
use std::convert::TryInto;
7771

@@ -83,13 +77,11 @@ mod test {
8377
let hash = vec![0x11, 0x22, 0x33];
8478
let key_name = "test name".to_string();
8579
proto.hash = hash.clone();
86-
proto.key_lifetime = key_attributes::KeyLifetime::Persistent as i32;
8780
proto.key_name = key_name.clone();
8881

8982
let op: OpAsymSign = proto.try_into().expect("Failed to convert");
9083

9184
assert_eq!(op.hash, hash);
92-
assert_eq!(op.key_lifetime, key_attributes::KeyLifetime::Persistent);
9385
assert_eq!(op.key_name, key_name);
9486
}
9587

@@ -100,17 +92,12 @@ mod test {
10092

10193
let op = OpAsymSign {
10294
hash: hash.clone(),
103-
key_lifetime: key_attributes::KeyLifetime::Persistent,
10495
key_name: key_name.clone(),
10596
};
10697

10798
let proto: OpAsymmetricSignProto = op.try_into().expect("Failed to convert");
10899

109100
assert_eq!(proto.hash, hash);
110-
assert_eq!(
111-
proto.key_lifetime,
112-
key_attributes::KeyLifetime::Persistent as i32
113-
);
114101
assert_eq!(proto.key_name, key_name);
115102
}
116103

@@ -141,7 +128,6 @@ mod test {
141128
fn op_asym_sign_e2e() {
142129
let op = OpAsymSign {
143130
hash: vec![0x11, 0x22, 0x33],
144-
key_lifetime: key_attributes::KeyLifetime::Persistent,
145131
key_name: "test name".to_string(),
146132
};
147133
let body = CONVERTER

src/operations_protobuf/convert_asym_verify.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use super::generated_ops::asym_verify::{OpAsymmetricVerifyProto, ResultAsymmetricVerifyProto};
1616
use crate::operations::{OpAsymVerify, ResultAsymVerify};
1717
use crate::requests::ResponseStatus;
18-
use num::FromPrimitive;
1918
use std::convert::TryFrom;
2019

2120
impl TryFrom<OpAsymmetricVerifyProto> for OpAsymVerify {
@@ -24,8 +23,6 @@ impl TryFrom<OpAsymmetricVerifyProto> for OpAsymVerify {
2423
fn try_from(proto_op: OpAsymmetricVerifyProto) -> Result<Self, Self::Error> {
2524
Ok(OpAsymVerify {
2625
key_name: proto_op.key_name,
27-
key_lifetime: FromPrimitive::from_i32(proto_op.key_lifetime)
28-
.expect("Failed to convert key lifetime"),
2926
hash: proto_op.hash,
3027
signature: proto_op.signature,
3128
})
@@ -38,7 +35,6 @@ impl TryFrom<OpAsymVerify> for OpAsymmetricVerifyProto {
3835
fn try_from(op: OpAsymVerify) -> Result<Self, Self::Error> {
3936
Ok(OpAsymmetricVerifyProto {
4037
key_name: op.key_name,
41-
key_lifetime: op.key_lifetime as i32,
4238
hash: op.hash,
4339
signature: op.signature,
4440
})
@@ -67,9 +63,7 @@ mod test {
6763
OpAsymmetricVerifyProto, ResultAsymmetricVerifyProto,
6864
};
6965
use super::super::{Convert, ProtobufConverter};
70-
use crate::operations::{
71-
key_attributes, NativeOperation, NativeResult, OpAsymVerify, ResultAsymVerify,
72-
};
66+
use crate::operations::{NativeOperation, NativeResult, OpAsymVerify, ResultAsymVerify};
7367
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode};
7468
use std::convert::TryInto;
7569

@@ -82,14 +76,12 @@ mod test {
8276
let key_name = "test name".to_string();
8377
let signature = vec![0x11, 0x22, 0x33];
8478
proto.hash = hash.clone();
85-
proto.key_lifetime = key_attributes::KeyLifetime::Persistent as i32;
8679
proto.key_name = key_name.clone();
8780
proto.signature = signature.clone();
8881

8982
let op: OpAsymVerify = proto.try_into().expect("Failed to convert");
9083

9184
assert_eq!(op.hash, hash);
92-
assert_eq!(op.key_lifetime, key_attributes::KeyLifetime::Persistent);
9385
assert_eq!(op.key_name, key_name);
9486
assert_eq!(op.signature, signature);
9587
}
@@ -102,18 +94,13 @@ mod test {
10294

10395
let op = OpAsymVerify {
10496
hash: hash.clone(),
105-
key_lifetime: key_attributes::KeyLifetime::Persistent,
10697
key_name: key_name.clone(),
10798
signature: signature.clone(),
10899
};
109100

110101
let proto: OpAsymmetricVerifyProto = op.try_into().expect("Failed to convert");
111102

112103
assert_eq!(proto.hash, hash);
113-
assert_eq!(
114-
proto.key_lifetime,
115-
key_attributes::KeyLifetime::Persistent as i32
116-
);
117104
assert_eq!(proto.key_name, key_name);
118105
assert_eq!(proto.signature, signature);
119106
}
@@ -136,7 +123,6 @@ mod test {
136123
fn op_asym_sign_e2e() {
137124
let op = OpAsymVerify {
138125
hash: vec![0x11, 0x22, 0x33],
139-
key_lifetime: key_attributes::KeyLifetime::Persistent,
140126
key_name: "test name".to_string(),
141127
signature: vec![0x11, 0x22, 0x33],
142128
};

src/operations_protobuf/convert_create_key.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ mod test {
130130

131131
fn get_key_attrs() -> KeyAttributes {
132132
KeyAttributes {
133-
key_lifetime: key_attributes::KeyLifetime::Persistent,
134133
key_type: key_attributes::KeyType::RsaKeypair,
135134
ecc_curve: Some(key_attributes::EccCurve::Secp160k1),
136135
algorithm: key_attributes::Algorithm::sign(
@@ -153,7 +152,6 @@ mod test {
153152
hash_algorithm: key_attributes_proto::HashAlgorithm::Sha1 as i32,
154153
}));
155154
KeyAttributesProto {
156-
key_lifetime: key_attributes_proto::KeyLifetime::Persistent as i32,
157155
key_type: key_attributes_proto::KeyType::RsaKeypair as i32,
158156
ecc_curve: key_attributes_proto::EccCurve::Secp160k1 as i32,
159157
algorithm_proto: algo,

src/operations_protobuf/convert_destroy_key.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use super::generated_ops::destroy_key::{OpDestroyKeyProto, ResultDestroyKeyProto};
1616
use crate::operations::{OpDestroyKey, ResultDestroyKey};
1717
use crate::requests::ResponseStatus;
18-
use num::FromPrimitive;
1918
use std::convert::TryFrom;
2019

2120
impl TryFrom<OpDestroyKeyProto> for OpDestroyKey {
@@ -24,8 +23,6 @@ impl TryFrom<OpDestroyKeyProto> for OpDestroyKey {
2423
fn try_from(proto_op: OpDestroyKeyProto) -> Result<Self, Self::Error> {
2524
Ok(OpDestroyKey {
2625
key_name: proto_op.key_name,
27-
key_lifetime: FromPrimitive::from_i32(proto_op.key_lifetime)
28-
.expect("Failed to convert key lifetime"),
2926
})
3027
}
3128
}
@@ -36,7 +33,6 @@ impl TryFrom<OpDestroyKey> for OpDestroyKeyProto {
3633
fn try_from(op: OpDestroyKey) -> Result<Self, Self::Error> {
3734
Ok(OpDestroyKeyProto {
3835
key_name: op.key_name,
39-
key_lifetime: op.key_lifetime as i32,
4036
})
4137
}
4238
}
@@ -61,7 +57,7 @@ impl TryFrom<ResultDestroyKey> for ResultDestroyKeyProto {
6157
mod test {
6258
use super::super::generated_ops::destroy_key::{OpDestroyKeyProto, ResultDestroyKeyProto};
6359
use super::super::{Convert, ProtobufConverter};
64-
use crate::operations::{key_attributes, NativeOperation, OpDestroyKey, ResultDestroyKey};
60+
use crate::operations::{NativeOperation, OpDestroyKey, ResultDestroyKey};
6561
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode};
6662
use std::convert::TryInto;
6763

@@ -71,29 +67,22 @@ mod test {
7167
fn destroy_key_proto_to_op() {
7268
let mut proto: OpDestroyKeyProto = Default::default();
7369
let key_name = "test name".to_string();
74-
proto.key_lifetime = key_attributes::KeyLifetime::Persistent as i32;
7570
proto.key_name = key_name.clone();
7671

7772
let op: OpDestroyKey = proto.try_into().expect("Failed to convert");
7873

79-
assert_eq!(op.key_lifetime, key_attributes::KeyLifetime::Persistent);
8074
assert_eq!(op.key_name, key_name);
8175
}
8276

8377
#[test]
8478
fn destroy_key_op_to_proto() {
8579
let key_name = "test name".to_string();
8680
let op = OpDestroyKey {
87-
key_lifetime: key_attributes::KeyLifetime::Persistent,
8881
key_name: key_name.clone(),
8982
};
9083

9184
let proto: OpDestroyKeyProto = op.try_into().expect("Failed to convert");
9285

93-
assert_eq!(
94-
proto.key_lifetime,
95-
key_attributes::KeyLifetime::Persistent as i32
96-
);
9786
assert_eq!(proto.key_name, key_name);
9887
}
9988

@@ -114,7 +103,6 @@ mod test {
114103
#[test]
115104
fn op_destroy_key_e2e() {
116105
let op = OpDestroyKey {
117-
key_lifetime: key_attributes::KeyLifetime::Persistent,
118106
key_name: "test name".to_string(),
119107
};
120108
let body = CONVERTER

0 commit comments

Comments
 (0)