std.crypto.x509.PrivateKey
type pub inline PrivateKeyAn X.509 private key.
This is currently just an opaque wrapper around a ByteArray.
Static methods
from_pem_file
Show source codeHide source code
fn pub static from_pem_file(
path: ref Path,
) -> Result[PrivateKey, ParseError] {
let file = match ReadOnlyFile.new(path) {
case Ok(v) -> pem.PemFile.new(v)
case Error(e) -> throw ParseError.Read(e)
}
match file.next_private_key {
case Ok(Some(v)) -> Result.Ok(v)
case Ok(None) -> throw ParseError.Missing
case Error(e) -> throw ParseError.Invalid(e)
}
}fn pub static from_pem_file(path: ref Path) -> Result[PrivateKey, ParseError]Parses the first private key from a PEM file.
For more control over the parsing of PEM files, use std.crypto.pem.PemFile
directly.
Errors
If the file is invalid or no private key is found, a ParseError error is
returned.
Examples
import std.crypto.x509
PrivateKey.from_pem_file('key.pem').or_panic # => Result.Ok(PrivateKey(...))
new
Show source codeHide source code
fn pub inline static new(bytes: ByteArray) -> PrivateKey {
PrivateKey(bytes)
}fn pub inline static new(bytes: ByteArray) -> PrivateKeyReturns a new PrivateKey that wraps the given ByteArray.
Instance methods
!=
Show source codeHide source code
fn pub !=(other: ref Self) -> Bool {
!(self == other)
}fn pub !=(other: ref Self) -> BoolReturns true if self and the given object are not equal to each other.
==
Show source codeHide source code
fn pub ==(other: ref PrivateKey) -> Bool {
@bytes == other.bytes
}fn pub ==(other: ref PrivateKey) -> BoolReturns true if self and the given object are equal to each other.
This operator is used to perform structural equality. This means two objects residing in different memory locations may be considered equal, provided their structure is equal. For example, two different arrays may be considered to have structural equality if they contain the exact same values.
fmt
Show source codeHide source code
fn pub fmt(formatter: mut Formatter) {
formatter.write('PrivateKey(${@bytes.size} bytes)')
}fn pub fmt(formatter: mut Formatter)Formats self in a human-readable format for debugging purposes.
Implemented traits
Equal
impl Equal for PrivateKeyFormat
impl Format for PrivateKey