跳到主要内容

PrivateKeyDer

搜索

枚举 PrivateKeyDer 

Source
#[non_exhaustive]
pub enum PrivateKeyDer<'a> { Pkcs1(PrivatePkcs1KeyDer<'a>), Sec1(PrivateSec1KeyDer<'a>), Pkcs8(PrivatePkcs8KeyDer<'a>), }
展开描述

一个 DER 编码的 X.509 私钥,可采用多种格式之一

更多信息请参见各变体的内部类型。

它可以加载多种类型的 PEM 编码私钥,并报告实际发现了哪些类型:

use rustls_pki_types::{PrivateKeyDer, pem::PemObject};

// load from a PEM file
let pkcs8 = PrivateKeyDer::from_pem_file("tests/data/nistp256key.pkcs8.pem").unwrap();
let pkcs1 = PrivateKeyDer::from_pem_file("tests/data/rsa1024.pkcs1.pem").unwrap();
let sec1 = PrivateKeyDer::from_pem_file("tests/data/nistp256key.pem").unwrap();
assert!(matches!(pkcs8, PrivateKeyDer::Pkcs8(_)));
assert!(matches!(pkcs1, PrivateKeyDer::Pkcs1(_)));
assert!(matches!(sec1, PrivateKeyDer::Sec1(_)));

变体 (Non-exhaustive)§

This enum is marked as non-exhaustive
非穷尽枚举未来可能添加新的变体。因此,在对非穷尽枚举的变体进行模式匹配时,必须额外增加一个通配符分支以涵盖未来的新变体。
§

Pkcs1(PrivatePkcs1KeyDer<'a>)

一份 RSA 私钥

§

Sec1(PrivateSec1KeyDer<'a>)

一份 Sec1 私钥

§

Pkcs8(PrivatePkcs8KeyDer<'a>)

一份 PKCS#8 私钥

实现§

Source§

impl PrivateKeyDer<'_>

Source

pub fn clone_key(&self) -> PrivateKeyDer<'static>

将该私钥克隆为一个 'static

Source

pub fn secret_der(&self) -> &[u8]

产出该私钥 DER 编码后的字节

trait 实现§

Source§

impl<'a> Debug for PrivateKeyDer<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

使用给定的格式化器格式化该值。更多信息
Source§

impl<'a> From<PrivatePkcs1KeyDer<'a>> for PrivateKeyDer<'a>

Source§

fn from(key: PrivatePkcs1KeyDer<'a>) -> Self

将该输入类型转换为此类型。
Source§

impl<'a> From<PrivatePkcs8KeyDer<'a>> for PrivateKeyDer<'a>

Source§

fn from(key: PrivatePkcs8KeyDer<'a>) -> Self

将该输入类型转换为此类型。
Source§

impl<'a> From<PrivateSec1KeyDer<'a>> for PrivateKeyDer<'a>

Source§

fn from(key: PrivateSec1KeyDer<'a>) -> Self

将该输入类型转换为此类型。
Source§

impl<'a> PartialEq for PrivateKeyDer<'a>

Source§

fn eq(&self, other: &PrivateKeyDer<'a>) -> bool

测试 selfother 值是否相等,供 == 使用。
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

测试 != 运算符。默认实现几乎总是够用,除非有非常充分的理由,否则不应被覆盖。
Source§

impl PemObject for PrivateKeyDer<'static>

Available on crate feature alloc only.
Source§

fn from_pem(kind: SectionKind, value: Vec<u8>) -> Option<Self>

从 PEM 的 SectionKind 与 body 数据进行转换。更多信息
Source§

fn from_pem_slice(pem: &[u8]) -> Result<Self, Error>

从一段字节切片中的 PEM 数据里,解码出本类型的第一个 section。更多信息
Source§

fn pem_slice_iter(pem: &[u8]) -> SliceIter<'_, Self>

对一段字节切片中的 PEM 数据,迭代出本类型的所有 section。
Source§

fn from_pem_file(file_name: impl AsRef<Path>) -> Result<Self, Error>

从指定文件中的 PEM 内容里,解码出本类型的第一个 section。更多信息
Source§

fn pem_file_iter( file_name: impl AsRef<Path>, ) -> Result<ReadIter<BufReader<File>, Self>, Error>

从指定文件中的 PEM 内容里,迭代出本类型的所有 section。更多信息
Source§

fn from_pem_reader(rd: impl Read) -> Result<Self, Error>

从某个 io::Read 读取的 PEM 中,解码出本类型的第一个 section。
Source§

fn pem_reader_iter<R: Read>(rd: R) -> ReadIter<BufReader<R>, Self>

从某个 io::Read 中的 PEM 数据里,迭代出本类型的所有 section。
Source§

impl<'a> TryFrom<&'a [u8]> for PrivateKeyDer<'a>

Source§

type Error = &'static str

转换出错时返回的类型。
Source§

fn try_from(key: &'a [u8]) -> Result<Self, Self::Error>

执行转换。
Source§

impl TryFrom<Vec<u8>> for PrivateKeyDer<'_>

Available on crate feature alloc only.
Source§

type Error = &'static str

转换出错时返回的类型。
Source§

fn try_from(key: Vec<u8>) -> Result<Self, Self::Error>

执行转换。
Source§

impl Zeroize for PrivateKeyDer<'static>

Available on crate feature alloc only.
Source§

fn zeroize(&mut self)

使用 Rust intrinsics 将本对象从内存中清零,确保零清除操作不会被编译器“优化掉”。
Source§

impl<'a> Eq for PrivateKeyDer<'a>

Source§

impl<'a> StructuralPartialEq for PrivateKeyDer<'a>

自动 trait 实现§

§

impl<'a> Freeze for PrivateKeyDer<'a>

§

impl<'a> RefUnwindSafe for PrivateKeyDer<'a>

§

impl<'a> Send for PrivateKeyDer<'a>

§

impl<'a> Sync for PrivateKeyDer<'a>

§

impl<'a> Unpin for PrivateKeyDer<'a>

§

impl<'a> UnsafeUnpin for PrivateKeyDer<'a>

§

impl<'a> UnwindSafe for PrivateKeyDer<'a>

blanket 实现§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. 更多信息
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 更多信息
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

原样返回参数。

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

调用 U::from(self)

即此转换的实际行为取决于 From<T> for U 的实现。

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

转换出错时返回的类型。
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

执行转换。
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

转换出错时返回的类型。
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

执行转换。