Skip to content

Commit 25c5d2e

Browse files
committed
Use infallible conversion into instead of try_into
A new clippy lint https://rust-lang.github.io/rust-clippy/master/index.html#/unnecessary_fallible_conversions has been added to rust 1.75.0 that is causing the CI failure. The use of try_into when into is available will be reported by the lint now. Signed-off-by: Gowtham Suresh Kumar <[email protected]>
1 parent 7d8252e commit 25c5d2e

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

cryptoki/src/context/session_management.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::context::Pkcs11;
88
use crate::error::{Result, Rv};
99
use crate::session::Session;
1010
use crate::slot::Slot;
11-
use std::convert::TryInto;
1211

1312
impl Pkcs11 {
1413
#[inline(always)]
@@ -22,7 +21,7 @@ impl Pkcs11 {
2221
};
2322
unsafe {
2423
Rv::from(get_pkcs11!(self, C_OpenSession)(
25-
slot_id.try_into()?,
24+
slot_id.into(),
2625
flags,
2726
// TODO: abstract those types or create new functions for callbacks
2827
std::ptr::null_mut(),

cryptoki/src/context/slot_token_management.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Pkcs11 {
8787
let label = label_from_str(label);
8888
unsafe {
8989
Rv::from(get_pkcs11!(self, C_InitToken)(
90-
slot.try_into()?,
90+
slot.into(),
9191
pin.expose_secret().as_ptr() as *mut u8,
9292
pin.expose_secret().len().try_into()?,
9393
label.as_ptr() as *mut u8,
@@ -101,7 +101,7 @@ impl Pkcs11 {
101101
unsafe {
102102
let mut slot_info = CK_SLOT_INFO::default();
103103
Rv::from(get_pkcs11!(self, C_GetSlotInfo)(
104-
slot.try_into()?,
104+
slot.into(),
105105
&mut slot_info,
106106
))
107107
.into_result()?;
@@ -114,7 +114,7 @@ impl Pkcs11 {
114114
unsafe {
115115
let mut token_info = CK_TOKEN_INFO::default();
116116
Rv::from(get_pkcs11!(self, C_GetTokenInfo)(
117-
slot.try_into()?,
117+
slot.into(),
118118
&mut token_info,
119119
))
120120
.into_result()?;
@@ -128,7 +128,7 @@ impl Pkcs11 {
128128

129129
unsafe {
130130
Rv::from(get_pkcs11!(self, C_GetMechanismList)(
131-
slot.try_into()?,
131+
slot.into(),
132132
std::ptr::null_mut(),
133133
&mut mechanism_count,
134134
))
@@ -139,7 +139,7 @@ impl Pkcs11 {
139139

140140
unsafe {
141141
Rv::from(get_pkcs11!(self, C_GetMechanismList)(
142-
slot.try_into()?,
142+
slot.into(),
143143
mechanisms.as_mut_ptr(),
144144
&mut mechanism_count,
145145
))
@@ -160,7 +160,7 @@ impl Pkcs11 {
160160
unsafe {
161161
let mut mechanism_info = CK_MECHANISM_INFO::default();
162162
Rv::from(get_pkcs11!(self, C_GetMechanismInfo)(
163-
slot.try_into()?,
163+
slot.into(),
164164
type_.into(),
165165
&mut mechanism_info,
166166
))

cryptoki/src/object.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -818,10 +818,10 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
818818
}
819819
// CK_ULONG
820820
AttributeType::ModulusBits => Ok(Attribute::ModulusBits(
821-
CK_ULONG::from_ne_bytes(val.try_into()?).try_into()?,
821+
CK_ULONG::from_ne_bytes(val.try_into()?).into(),
822822
)),
823823
AttributeType::ValueLen => Ok(Attribute::ValueLen(
824-
CK_ULONG::from_ne_bytes(val.try_into()?).try_into()?,
824+
CK_ULONG::from_ne_bytes(val.try_into()?).into(),
825825
)),
826826
// Vec<u8>
827827
AttributeType::AcIssuer => Ok(Attribute::AcIssuer(val.to_vec())),

cryptoki/src/session/random.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Session {
3333
Rv::from(get_pkcs11!(self.client(), C_GenerateRandom)(
3434
self.handle(),
3535
result.as_mut_ptr(),
36-
random_len.try_into()?,
36+
random_len.into(),
3737
))
3838
.into_result()?;
3939
}

cryptoki/src/slot/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl TryFrom<u32> for Slot {
6464

6565
fn try_from(slot_id: u32) -> Result<Self> {
6666
Ok(Self {
67-
slot_id: slot_id.try_into()?,
67+
slot_id: slot_id.into(),
6868
})
6969
}
7070
}

0 commit comments

Comments
 (0)