Skip to content

Remove references to key lifetime #5

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

Merged
merged 1 commit into from
Oct 23, 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
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::process::{Command, Output};

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

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

Expand Down
4 changes: 1 addition & 3 deletions src/operations/asym_sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use super::key_attributes::KeyLifetime;

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

Expand Down
4 changes: 1 addition & 3 deletions src/operations/asym_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use super::key_attributes::KeyLifetime;

/// Native object for asymmetric verification of signatures.
///
/// `key_name` and `key_lifetime` specify the key to be used for verification.
/// `key_name` specifies the key to be used for verification.
/// The `hash` contains a short message or hash value as described for the
/// asymmetric signing operation.
/// `signature` contains the bytes of the signature which requires validation and must
/// follow any format requirements imposed by the provider.
#[derive(Debug)]
pub struct OpAsymVerify {
pub key_name: String,
pub key_lifetime: KeyLifetime,
pub hash: Vec<u8>,
pub signature: Vec<u8>,
}
Expand Down
4 changes: 1 addition & 3 deletions src/operations/destroy_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use super::key_attributes::KeyLifetime;

/// Native object for cryptographic key destruction.
///
/// `key_name` and `key_lifetime` identify the key to be destroyed.
/// `key_name` identifies the key to be destroyed.
#[derive(Debug, Clone)]
pub struct OpDestroyKey {
pub key_name: String,
pub key_lifetime: KeyLifetime,
}

/// Native object for result of cryptographic key destruction.
Expand Down
4 changes: 1 addition & 3 deletions src/operations/export_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use super::key_attributes::KeyLifetime;

/// Native object for public key exporting operation.
///
/// `key_name` and `key_lifetime` identify the key for which the public
/// `key_name` identifies the key for which the public
/// part will be exported. The specified key must be an asymmetric keypair.
pub struct OpExportPublicKey {
pub key_name: String,
pub key_lifetime: KeyLifetime,
}

/// Native object for result of public key export operation.
Expand Down
9 changes: 0 additions & 9 deletions src/operations/key_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ impl Algorithm {
/// a cryptographic key.
#[derive(Clone)]
pub struct KeyAttributes {
pub key_lifetime: KeyLifetime,
pub key_type: KeyType,
pub ecc_curve: Option<EccCurve>,
pub algorithm: Algorithm,
Expand All @@ -111,14 +110,6 @@ pub struct KeyAttributes {
pub permit_derive: bool,
}

#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[repr(i32)]
pub enum KeyLifetime {
Volatile = 0,
Persistent = 1,
}

/// Enumeration of key types supported.
#[derive(FromPrimitive, Copy, Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
Expand Down
16 changes: 1 addition & 15 deletions src/operations_protobuf/convert_asym_sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use super::generated_ops::asym_sign::{OpAsymmetricSignProto, ResultAsymmetricSignProto};
use crate::operations::{OpAsymSign, ResultAsymSign};
use crate::requests::ResponseStatus;
use num::FromPrimitive;
use std::convert::TryFrom;

impl TryFrom<OpAsymmetricSignProto> for OpAsymSign {
Expand All @@ -24,8 +23,6 @@ impl TryFrom<OpAsymmetricSignProto> for OpAsymSign {
fn try_from(proto_op: OpAsymmetricSignProto) -> Result<Self, Self::Error> {
Ok(OpAsymSign {
key_name: proto_op.key_name,
key_lifetime: FromPrimitive::from_i32(proto_op.key_lifetime)
.expect("Failed to convert key lifetime"),
hash: proto_op.hash,
})
}
Expand All @@ -37,7 +34,6 @@ impl TryFrom<OpAsymSign> for OpAsymmetricSignProto {
fn try_from(op: OpAsymSign) -> Result<Self, Self::Error> {
Ok(OpAsymmetricSignProto {
key_name: op.key_name,
key_lifetime: op.key_lifetime as i32,
hash: op.hash,
})
}
Expand Down Expand Up @@ -69,9 +65,7 @@ mod test {
OpAsymmetricSignProto, ResultAsymmetricSignProto,
};
use super::super::{Convert, ProtobufConverter};
use crate::operations::{
key_attributes, NativeOperation, NativeResult, OpAsymSign, ResultAsymSign,
};
use crate::operations::{NativeOperation, NativeResult, OpAsymSign, ResultAsymSign};
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode};
use std::convert::TryInto;

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

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

assert_eq!(op.hash, hash);
assert_eq!(op.key_lifetime, key_attributes::KeyLifetime::Persistent);
assert_eq!(op.key_name, key_name);
}

Expand All @@ -100,17 +92,12 @@ mod test {

let op = OpAsymSign {
hash: hash.clone(),
key_lifetime: key_attributes::KeyLifetime::Persistent,
key_name: key_name.clone(),
};

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

assert_eq!(proto.hash, hash);
assert_eq!(
proto.key_lifetime,
key_attributes::KeyLifetime::Persistent as i32
);
assert_eq!(proto.key_name, key_name);
}

Expand Down Expand Up @@ -141,7 +128,6 @@ mod test {
fn op_asym_sign_e2e() {
let op = OpAsymSign {
hash: vec![0x11, 0x22, 0x33],
key_lifetime: key_attributes::KeyLifetime::Persistent,
key_name: "test name".to_string(),
};
let body = CONVERTER
Expand Down
16 changes: 1 addition & 15 deletions src/operations_protobuf/convert_asym_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use super::generated_ops::asym_verify::{OpAsymmetricVerifyProto, ResultAsymmetricVerifyProto};
use crate::operations::{OpAsymVerify, ResultAsymVerify};
use crate::requests::ResponseStatus;
use num::FromPrimitive;
use std::convert::TryFrom;

impl TryFrom<OpAsymmetricVerifyProto> for OpAsymVerify {
Expand All @@ -24,8 +23,6 @@ impl TryFrom<OpAsymmetricVerifyProto> for OpAsymVerify {
fn try_from(proto_op: OpAsymmetricVerifyProto) -> Result<Self, Self::Error> {
Ok(OpAsymVerify {
key_name: proto_op.key_name,
key_lifetime: FromPrimitive::from_i32(proto_op.key_lifetime)
.expect("Failed to convert key lifetime"),
hash: proto_op.hash,
signature: proto_op.signature,
})
Expand All @@ -38,7 +35,6 @@ impl TryFrom<OpAsymVerify> for OpAsymmetricVerifyProto {
fn try_from(op: OpAsymVerify) -> Result<Self, Self::Error> {
Ok(OpAsymmetricVerifyProto {
key_name: op.key_name,
key_lifetime: op.key_lifetime as i32,
hash: op.hash,
signature: op.signature,
})
Expand Down Expand Up @@ -67,9 +63,7 @@ mod test {
OpAsymmetricVerifyProto, ResultAsymmetricVerifyProto,
};
use super::super::{Convert, ProtobufConverter};
use crate::operations::{
key_attributes, NativeOperation, NativeResult, OpAsymVerify, ResultAsymVerify,
};
use crate::operations::{NativeOperation, NativeResult, OpAsymVerify, ResultAsymVerify};
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode};
use std::convert::TryInto;

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

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

assert_eq!(op.hash, hash);
assert_eq!(op.key_lifetime, key_attributes::KeyLifetime::Persistent);
assert_eq!(op.key_name, key_name);
assert_eq!(op.signature, signature);
}
Expand All @@ -102,18 +94,13 @@ mod test {

let op = OpAsymVerify {
hash: hash.clone(),
key_lifetime: key_attributes::KeyLifetime::Persistent,
key_name: key_name.clone(),
signature: signature.clone(),
};

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

assert_eq!(proto.hash, hash);
assert_eq!(
proto.key_lifetime,
key_attributes::KeyLifetime::Persistent as i32
);
assert_eq!(proto.key_name, key_name);
assert_eq!(proto.signature, signature);
}
Expand All @@ -136,7 +123,6 @@ mod test {
fn op_asym_sign_e2e() {
let op = OpAsymVerify {
hash: vec![0x11, 0x22, 0x33],
key_lifetime: key_attributes::KeyLifetime::Persistent,
key_name: "test name".to_string(),
signature: vec![0x11, 0x22, 0x33],
};
Expand Down
2 changes: 0 additions & 2 deletions src/operations_protobuf/convert_create_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ mod test {

fn get_key_attrs() -> KeyAttributes {
KeyAttributes {
key_lifetime: key_attributes::KeyLifetime::Persistent,
key_type: key_attributes::KeyType::RsaKeypair,
ecc_curve: Some(key_attributes::EccCurve::Secp160k1),
algorithm: key_attributes::Algorithm::sign(
Expand All @@ -153,7 +152,6 @@ mod test {
hash_algorithm: key_attributes_proto::HashAlgorithm::Sha1 as i32,
}));
KeyAttributesProto {
key_lifetime: key_attributes_proto::KeyLifetime::Persistent as i32,
key_type: key_attributes_proto::KeyType::RsaKeypair as i32,
ecc_curve: key_attributes_proto::EccCurve::Secp160k1 as i32,
algorithm_proto: algo,
Expand Down
14 changes: 1 addition & 13 deletions src/operations_protobuf/convert_destroy_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use super::generated_ops::destroy_key::{OpDestroyKeyProto, ResultDestroyKeyProto};
use crate::operations::{OpDestroyKey, ResultDestroyKey};
use crate::requests::ResponseStatus;
use num::FromPrimitive;
use std::convert::TryFrom;

impl TryFrom<OpDestroyKeyProto> for OpDestroyKey {
Expand All @@ -24,8 +23,6 @@ impl TryFrom<OpDestroyKeyProto> for OpDestroyKey {
fn try_from(proto_op: OpDestroyKeyProto) -> Result<Self, Self::Error> {
Ok(OpDestroyKey {
key_name: proto_op.key_name,
key_lifetime: FromPrimitive::from_i32(proto_op.key_lifetime)
.expect("Failed to convert key lifetime"),
})
}
}
Expand All @@ -36,7 +33,6 @@ impl TryFrom<OpDestroyKey> for OpDestroyKeyProto {
fn try_from(op: OpDestroyKey) -> Result<Self, Self::Error> {
Ok(OpDestroyKeyProto {
key_name: op.key_name,
key_lifetime: op.key_lifetime as i32,
})
}
}
Expand All @@ -61,7 +57,7 @@ impl TryFrom<ResultDestroyKey> for ResultDestroyKeyProto {
mod test {
use super::super::generated_ops::destroy_key::{OpDestroyKeyProto, ResultDestroyKeyProto};
use super::super::{Convert, ProtobufConverter};
use crate::operations::{key_attributes, NativeOperation, OpDestroyKey, ResultDestroyKey};
use crate::operations::{NativeOperation, OpDestroyKey, ResultDestroyKey};
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode};
use std::convert::TryInto;

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

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

assert_eq!(op.key_lifetime, key_attributes::KeyLifetime::Persistent);
assert_eq!(op.key_name, key_name);
}

#[test]
fn destroy_key_op_to_proto() {
let key_name = "test name".to_string();
let op = OpDestroyKey {
key_lifetime: key_attributes::KeyLifetime::Persistent,
key_name: key_name.clone(),
};

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

assert_eq!(
proto.key_lifetime,
key_attributes::KeyLifetime::Persistent as i32
);
assert_eq!(proto.key_name, key_name);
}

Expand All @@ -114,7 +103,6 @@ mod test {
#[test]
fn op_destroy_key_e2e() {
let op = OpDestroyKey {
key_lifetime: key_attributes::KeyLifetime::Persistent,
key_name: "test name".to_string(),
};
let body = CONVERTER
Expand Down
Loading