Skip to content

Commit b10d69c

Browse files
authored
Merge pull request #307 from ionut-arm/no-ref
Update API to take ownership where needed
2 parents eece692 + 471f9fc commit b10d69c

39 files changed

+353
-331
lines changed

tss-esapi/src/abstraction/ak.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn create_ak_public<IKC: IntoKeyCustomization>(
6767
.with_restricted(obj_attrs.restricted())
6868
.build()?,
6969
)
70-
.with_rsa_unique_identifier(&PublicKeyRsa::default())
70+
.with_rsa_unique_identifier(PublicKeyRsa::default())
7171
.build(),
7272
AsymmetricAlgorithm::Ecc => PublicBuilder::new()
7373
.with_public_algorithm(PublicAlgorithm::Ecc)
@@ -97,7 +97,7 @@ fn create_ak_public<IKC: IntoKeyCustomization>(
9797
pub fn load_ak(
9898
context: &mut Context,
9999
parent: KeyHandle,
100-
ak_auth_value: Option<&Auth>,
100+
ak_auth_value: Option<Auth>,
101101
private: Private,
102102
public: Public,
103103
) -> Result<KeyHandle> {
@@ -137,7 +137,7 @@ pub fn load_ak(
137137
})?;
138138

139139
ctx.execute_with_session(Some(policy_auth_session), |ctx| {
140-
ctx.load(parent, private, &public)
140+
ctx.load(parent, private, public)
141141
})
142142
},
143143
)?;
@@ -155,7 +155,7 @@ pub fn create_ak<IKC: IntoKeyCustomization>(
155155
parent: KeyHandle,
156156
hash_alg: HashingAlgorithm,
157157
sign_alg: SignatureSchemeAlgorithm,
158-
ak_auth_value: Option<&Auth>,
158+
ak_auth_value: Option<Auth>,
159159
key_customization: IKC,
160160
) -> Result<CreateKeyResult> {
161161
let key_alg = AsymmetricAlgorithm::try_from(sign_alg).map_err(|e| {
@@ -202,7 +202,7 @@ pub fn create_ak<IKC: IntoKeyCustomization>(
202202
})?;
203203

204204
ctx.execute_with_session(Some(policy_auth_session), |ctx| {
205-
ctx.create(parent, &ak_pub, ak_auth_value, None, None, None)
205+
ctx.create(parent, ak_pub, ak_auth_value, None, None, None)
206206
})
207207
},
208208
)

tss-esapi/src/abstraction/ek.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn create_ek_public_from_default_template<IKC: IntoKeyCustomization>(
6969
.with_public_algorithm(PublicAlgorithm::Rsa)
7070
.with_name_hashing_algorithm(HashingAlgorithm::Sha256)
7171
.with_object_attributes(obj_attrs)
72-
.with_auth_policy(&Digest::try_from(authpolicy[0..32].to_vec())?)
72+
.with_auth_policy(Digest::try_from(authpolicy[0..32].to_vec())?)
7373
.with_rsa_parameters(
7474
PublicRsaParametersBuilder::new()
7575
.with_symmetric(SymmetricDefinitionObject::AES_128_CFB)
@@ -81,12 +81,12 @@ pub fn create_ek_public_from_default_template<IKC: IntoKeyCustomization>(
8181
.with_restricted(obj_attrs.decrypt())
8282
.build()?,
8383
)
84-
.with_rsa_unique_identifier(&PublicKeyRsa::new_empty_with_size(RsaKeyBits::Rsa2048)),
84+
.with_rsa_unique_identifier(PublicKeyRsa::new_empty_with_size(RsaKeyBits::Rsa2048)),
8585
AsymmetricAlgorithm::Ecc => PublicBuilder::new()
8686
.with_public_algorithm(PublicAlgorithm::Ecc)
8787
.with_name_hashing_algorithm(HashingAlgorithm::Sha256)
8888
.with_object_attributes(obj_attrs)
89-
.with_auth_policy(&Digest::try_from(authpolicy[0..32].to_vec())?)
89+
.with_auth_policy(Digest::try_from(authpolicy[0..32].to_vec())?)
9090
.with_ecc_parameters(
9191
PublicEccParametersBuilder::new()
9292
.with_symmetric(SymmetricDefinitionObject::AES_128_CFB)
@@ -98,7 +98,7 @@ pub fn create_ek_public_from_default_template<IKC: IntoKeyCustomization>(
9898
.with_restricted(obj_attrs.decrypt())
9999
.build()?,
100100
)
101-
.with_ecc_unique_identifier(&EccPoint::new(
101+
.with_ecc_unique_identifier(EccPoint::new(
102102
EccParameter::try_from(vec![0u8; 32])?,
103103
EccParameter::try_from(vec![0u8; 32])?,
104104
)),
@@ -126,7 +126,7 @@ pub fn create_ek_object<IKC: IntoKeyCustomization>(
126126

127127
Ok(context
128128
.execute_with_nullauth_session(|ctx| {
129-
ctx.create_primary(Hierarchy::Endorsement, &ek_public, None, None, None, None)
129+
ctx.create_primary(Hierarchy::Endorsement, ek_public, None, None, None, None)
130130
})?
131131
.key_handle)
132132
}

tss-esapi/src/abstraction/pcr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn read_all(
6363
) -> Result<PcrData> {
6464
let mut pcr_data = PcrData::new();
6565
while !pcr_selection_list.is_empty() {
66-
let (_, pcrs_read, pcr_digests) = context.pcr_read(&pcr_selection_list)?;
66+
let (_, pcrs_read, pcr_digests) = context.pcr_read(pcr_selection_list.clone())?;
6767
pcr_data.add(&pcrs_read, &pcr_digests)?;
6868
pcr_selection_list.subtract(&pcrs_read)?;
6969
}

tss-esapi/src/abstraction/transient/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ impl TransientKeyContext {
154154
..
155155
} = self.context.create(
156156
self.root_key_handle,
157-
&TransientKeyContext::get_public_from_params(key_params, None)?,
158-
key_auth.as_ref(),
157+
TransientKeyContext::get_public_from_params(key_params, None)?,
158+
key_auth.clone(),
159159
None,
160160
None,
161161
None,
@@ -180,7 +180,7 @@ impl TransientKeyContext {
180180
self.set_session_attrs()?;
181181
let key_handle = self
182182
.context
183-
.load_external_public(&public, Hierarchy::Owner)?;
183+
.load_external_public(public, Hierarchy::Owner)?;
184184
self.context.flush_context(key_handle.into())?;
185185
Ok(KeyMaterial {
186186
public: public_key,
@@ -286,7 +286,7 @@ impl TransientKeyContext {
286286
.context
287287
.sign(
288288
key_handle,
289-
&digest,
289+
digest,
290290
SignatureScheme::Null,
291291
validation.try_into()?,
292292
)
@@ -317,7 +317,7 @@ impl TransientKeyContext {
317317
self.set_session_attrs()?;
318318
let verified = self
319319
.context
320-
.verify_signature(key_handle, &digest, signature)
320+
.verify_signature(key_handle, digest, signature)
321321
.or_else(|e| {
322322
self.context.flush_context(key_handle.into())?;
323323
Err(e)
@@ -341,7 +341,7 @@ impl TransientKeyContext {
341341
) -> Result<KeyMaterial> {
342342
self.set_session_attrs()?;
343343
let key_handle = self.context.context_load(context).map(KeyHandle::from)?;
344-
if let Some(key_auth_value) = &auth {
344+
if let Some(key_auth_value) = auth.clone() {
345345
self.context
346346
.tr_set_auth(key_handle.into(), key_auth_value)
347347
.or_else(|e| {
@@ -466,7 +466,7 @@ impl TransientKeyContext {
466466
.with_restricted(false)
467467
.build()?,
468468
)
469-
.with_rsa_unique_identifier(&unique);
469+
.with_rsa_unique_identifier(unique);
470470
}
471471
KeyParams::Ecc { scheme, curve } => {
472472
let unique = pub_key
@@ -484,7 +484,7 @@ impl TransientKeyContext {
484484
PublicEccParametersBuilder::new_unrestricted_signing_key(scheme, curve)
485485
.build()?,
486486
)
487-
.with_ecc_unique_identifier(&unique);
487+
.with_ecc_unique_identifier(unique);
488488
}
489489
}
490490
pub_builder.build()
@@ -504,16 +504,16 @@ impl TransientKeyContext {
504504
self.set_session_attrs()?;
505505
let key_handle = if material.private.is_empty() {
506506
self.context
507-
.load_external_public(&public, Hierarchy::Owner)?
507+
.load_external_public(public, Hierarchy::Owner)?
508508
} else {
509509
self.context
510-
.load(self.root_key_handle, material.private.try_into()?, &public)
510+
.load(self.root_key_handle, material.private.try_into()?, public)
511511
.map(KeyHandle::from)?
512512
};
513513
let key_auth_value = auth.unwrap_or_default();
514514
if !key_auth_value.is_empty() {
515515
self.context
516-
.tr_set_auth(key_handle.into(), &key_auth_value)
516+
.tr_set_auth(key_handle.into(), key_auth_value)
517517
.or_else(|e| {
518518
self.context.flush_context(key_handle.into())?;
519519
Err(e)
@@ -646,7 +646,7 @@ impl TransientKeyContextBuilder {
646646

647647
for (hierarchy, auth) in self.hierarchy_auth.drain() {
648648
let auth_hierarchy = Auth::try_from(auth)?;
649-
context.tr_set_auth(hierarchy.into(), &auth_hierarchy)?;
649+
context.tr_set_auth(hierarchy.into(), auth_hierarchy)?;
650650
}
651651

652652
let session = context
@@ -674,12 +674,12 @@ impl TransientKeyContextBuilder {
674674
let root_key_handle = context
675675
.create_primary(
676676
self.root_hierarchy,
677-
&create_restricted_decryption_rsa_public(
677+
create_restricted_decryption_rsa_public(
678678
self.default_context_cipher,
679679
root_key_rsa_key_bits,
680680
RsaExponent::ZERO_EXPONENT,
681681
)?,
682-
root_key_auth.as_ref(),
682+
root_key_auth,
683683
None,
684684
None,
685685
None,

tss-esapi/src/context/general_esys_tr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use zeroize::Zeroize;
2020

2121
impl Context {
2222
/// Set the authentication value for a given object handle in the ESYS context.
23-
pub fn tr_set_auth(&mut self, object_handle: ObjectHandle, auth: &Auth) -> Result<()> {
24-
let mut tss_auth = auth.clone().into();
23+
pub fn tr_set_auth(&mut self, object_handle: ObjectHandle, auth: Auth) -> Result<()> {
24+
let mut tss_auth = auth.into();
2525
let ret = unsafe { Esys_TR_SetAuth(self.mut_context(), object_handle.into(), &tss_auth) };
2626
tss_auth.buffer.zeroize();
2727
let ret = Error::from_tss_rc(ret);

tss-esapi/src/context/tpm_commands/asymmetric_primitives.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ impl Context {
166166
/// .with_name_hashing_algorithm(HashingAlgorithm::Sha256)
167167
/// .with_object_attributes(object_attributes)
168168
/// .with_ecc_parameters(ecc_parms)
169-
/// .with_ecc_unique_identifier(&EccPoint::default())
169+
/// .with_ecc_unique_identifier(EccPoint::default())
170170
/// .build()
171171
/// .unwrap();
172172
///
173173
/// let key_handle = context
174174
/// .create_primary(
175175
/// Hierarchy::Owner,
176-
/// &public,
177-
/// Some(&key_auth),
176+
/// public,
177+
/// Some(key_auth),
178178
/// None,
179179
/// None,
180180
/// None,
@@ -298,15 +298,15 @@ impl Context {
298298
/// .with_name_hashing_algorithm(HashingAlgorithm::Sha256)
299299
/// .with_object_attributes(object_attributes)
300300
/// .with_ecc_parameters(ecc_parms)
301-
/// .with_ecc_unique_identifier(&EccPoint::default())
301+
/// .with_ecc_unique_identifier(EccPoint::default())
302302
/// .build()
303303
/// .unwrap();
304304
///
305305
/// let key_handle = context
306306
/// .create_primary(
307307
/// Hierarchy::Owner,
308-
/// &public,
309-
/// Some(&key_auth),
308+
/// public,
309+
/// Some(key_auth),
310310
/// None,
311311
/// None,
312312
/// None,

tss-esapi/src/context/tpm_commands/attestation_commands.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Context {
7373
/// # .expect("Failed to create an unrestricted signing rsa public structure");
7474
/// # let sign_key_handle = context
7575
/// # .execute_with_nullauth_session(|ctx| {
76-
/// # ctx.create_primary(Hierarchy::Owner, &signing_key_pub, None, None, None, None)
76+
/// # ctx.create_primary(Hierarchy::Owner, signing_key_pub, None, None, None, None)
7777
/// # })
7878
/// # .unwrap()
7979
/// # .key_handle;
@@ -89,7 +89,7 @@ impl Context {
8989
/// # .execute_with_nullauth_session(|ctx| {
9090
/// # ctx.create_primary(
9191
/// # Hierarchy::Owner,
92-
/// # &decryption_key_pub,
92+
/// # decryption_key_pub,
9393
/// # None,
9494
/// # None,
9595
/// # None,
@@ -109,7 +109,7 @@ impl Context {
109109
/// ctx.certify(
110110
/// obj_key_handle.into(),
111111
/// sign_key_handle,
112-
/// &Data::try_from(qualifying_data).unwrap(),
112+
/// Data::try_from(qualifying_data).unwrap(),
113113
/// SignatureScheme::Null,
114114
/// )
115115
/// },
@@ -120,7 +120,7 @@ impl Context {
120120
&mut self,
121121
object_handle: ObjectHandle,
122122
signing_key_handle: KeyHandle,
123-
qualifying_data: &Data,
123+
qualifying_data: Data,
124124
signing_scheme: SignatureScheme,
125125
) -> Result<(Attest, Signature)> {
126126
let mut certify_info = null_mut();
@@ -133,7 +133,7 @@ impl Context {
133133
self.required_session_1()?,
134134
self.required_session_2()?,
135135
self.optional_session_3(),
136-
&qualifying_data.clone().into(),
136+
&qualifying_data.into(),
137137
&signing_scheme.into(),
138138
&mut certify_info,
139139
&mut signature,
@@ -163,7 +163,7 @@ impl Context {
163163
pub fn quote(
164164
&mut self,
165165
signing_key_handle: KeyHandle,
166-
qualifying_data: &Data,
166+
qualifying_data: Data,
167167
signing_scheme: SignatureScheme,
168168
pcr_selection_list: PcrSelectionList,
169169
) -> Result<(Attest, Signature)> {
@@ -176,7 +176,7 @@ impl Context {
176176
self.optional_session_1(),
177177
self.optional_session_2(),
178178
self.optional_session_3(),
179-
&qualifying_data.clone().into(),
179+
&qualifying_data.into(),
180180
&signing_scheme.into(),
181181
&pcr_selection_list.into(),
182182
&mut quoted,

tss-esapi/src/context/tpm_commands/context_management.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ impl Context {
125125
/// let key_handle = ctx
126126
/// .create_primary(
127127
/// Hierarchy::Owner,
128-
/// &public_area,
129-
/// Some(&key_auth),
128+
/// public_area,
129+
/// Some(key_auth),
130130
/// None,
131131
/// None,
132132
/// None,
@@ -245,12 +245,12 @@ impl Context {
245245
/// # ctx
246246
/// # .create_primary(
247247
/// # Hierarchy::Owner,
248-
/// # &create_restricted_decryption_rsa_public(
248+
/// # create_restricted_decryption_rsa_public(
249249
/// # SymmetricDefinitionObject::AES_256_CFB,
250250
/// # RsaKeyBits::Rsa2048,
251251
/// # RsaExponent::default(),
252252
/// # ).expect("Failed to Public structure for key"),
253-
/// # Some(auth_value_primary).as_ref(),
253+
/// # Some(auth_value_primary),
254254
/// # None,
255255
/// # None,
256256
/// # None,
@@ -364,12 +364,12 @@ impl Context {
364364
/// # ctx
365365
/// # .create_primary(
366366
/// # Hierarchy::Owner,
367-
/// # &create_restricted_decryption_rsa_public(
367+
/// # create_restricted_decryption_rsa_public(
368368
/// # SymmetricDefinitionObject::AES_256_CFB,
369369
/// # RsaKeyBits::Rsa2048,
370370
/// # RsaExponent::default(),
371371
/// # ).expect("Failed to Public structure for key"),
372-
/// # Some(auth_value_primary).as_ref(),
372+
/// # Some(auth_value_primary),
373373
/// # None,
374374
/// # None,
375375
/// # None,

0 commit comments

Comments
 (0)