Skip to content

Commit 1cf577e

Browse files
committed
pkcs8: move implement to &[u8]/Box<[u8]>
Signed-off-by: Arthur Gautier <[email protected]>
1 parent ae56ced commit 1cf577e

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

pkcs8/src/private_key_info.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ use crate::{Error, Result, Version};
44
use core::fmt;
55
use der::{
66
asn1::{AnyRef, BitStringRef, ContextSpecific, OctetStringRef},
7-
BytesRef, Decode, DecodeValue, Encode, EncodeValue, Header, Length, Reader, Sequence, TagMode,
8-
TagNumber, Writer,
7+
Decode, DecodeValue, Encode, EncodeValue, Header, Length, Reader, Sequence, TagMode, TagNumber,
8+
Writer,
99
};
1010
use spki::AlgorithmIdentifier;
1111

1212
#[cfg(feature = "alloc")]
13-
use der::{asn1::Any, BytesOwned, SecretDocument};
13+
use {
14+
alloc::boxed::Box,
15+
der::{asn1::Any, SecretDocument},
16+
};
1417

1518
#[cfg(feature = "encryption")]
1619
use {
@@ -129,7 +132,7 @@ impl<Params, Key> PrivateKeyInfo<Params, Key> {
129132
impl<'a, Params, Key> PrivateKeyInfo<Params, Key>
130133
where
131134
Params: der::Choice<'a> + Encode,
132-
Key: TryFrom<&'a [u8], Error = der::Error> + AsRef<[u8]>,
135+
Key: From<&'a [u8]> + AsRef<[u8]>,
133136
{
134137
/// Encrypt this private key using a symmetric encryption key derived
135138
/// from the provided password.
@@ -186,7 +189,7 @@ where
186189
impl<'a, Params, Key> DecodeValue<'a> for PrivateKeyInfo<Params, Key>
187190
where
188191
Params: der::Choice<'a> + Encode,
189-
Key: TryFrom<&'a [u8], Error = der::Error>,
192+
Key: From<&'a [u8]>,
190193
{
191194
fn decode_value<R: Reader<'a>>(
192195
reader: &mut R,
@@ -203,7 +206,7 @@ where
203206
.map(|bs| {
204207
bs.as_bytes()
205208
.ok_or_else(|| der::Tag::BitString.value_error())
206-
.and_then(Key::try_from)
209+
.map(Key::from)
207210
})
208211
.transpose()?;
209212

@@ -256,14 +259,14 @@ where
256259
impl<'a, Params, Key> Sequence<'a> for PrivateKeyInfo<Params, Key>
257260
where
258261
Params: der::Choice<'a> + Encode,
259-
Key: TryFrom<&'a [u8], Error = der::Error> + AsRef<[u8]>,
262+
Key: From<&'a [u8]> + AsRef<[u8]>,
260263
{
261264
}
262265

263266
impl<'a, Params, Key> TryFrom<&'a [u8]> for PrivateKeyInfo<Params, Key>
264267
where
265268
Params: der::Choice<'a> + Encode,
266-
Key: TryFrom<&'a [u8], Error = der::Error> + AsRef<[u8]>,
269+
Key: From<&'a [u8]> + AsRef<[u8]>,
267270
{
268271
type Error = Error;
269272

@@ -290,7 +293,7 @@ where
290293
impl<'a, Params, Key> TryFrom<PrivateKeyInfo<Params, Key>> for SecretDocument
291294
where
292295
Params: der::Choice<'a> + Encode,
293-
Key: TryFrom<&'a [u8], Error = der::Error> + AsRef<[u8]>,
296+
Key: From<&'a [u8]> + AsRef<[u8]>,
294297
{
295298
type Error = Error;
296299

@@ -303,7 +306,7 @@ where
303306
impl<'a, Params, Key> TryFrom<&PrivateKeyInfo<Params, Key>> for SecretDocument
304307
where
305308
Params: der::Choice<'a> + Encode,
306-
Key: TryFrom<&'a [u8], Error = der::Error> + AsRef<[u8]>,
309+
Key: From<&'a [u8]> + AsRef<[u8]>,
307310
{
308311
type Error = Error;
309312

@@ -352,12 +355,12 @@ where
352355
}
353356
}
354357

355-
/// [`PrivateKeyInfo`] with [`AnyRef`] algorithm parameters, and [`BytesRef`] key.
356-
pub type PrivateKeyInfoRef<'a> = PrivateKeyInfo<AnyRef<'a>, BytesRef<'a>>;
358+
/// [`PrivateKeyInfo`] with [`AnyRef`] algorithm parameters, and `&[u8]` key.
359+
pub type PrivateKeyInfoRef<'a> = PrivateKeyInfo<AnyRef<'a>, &'a [u8]>;
357360

358-
/// [`PrivateKeyInfo`] with [`Any`] algorithm parameters, and [`BytesOwned`] key.
361+
/// [`PrivateKeyInfo`] with [`Any`] algorithm parameters, and `Box<[u8]>` key.
359362
#[cfg(feature = "alloc")]
360-
pub type PrivateKeyInfoOwned = PrivateKeyInfo<Any, BytesOwned>;
363+
pub type PrivateKeyInfoOwned = PrivateKeyInfo<Any, Box<[u8]>>;
361364

362365
#[cfg(feature = "alloc")]
363366
mod allocating {

0 commit comments

Comments
 (0)