Search results

There are no results.

std.crypto.x509.PrivateKey

type pub inline PrivateKey

An X.509 private key.

This is currently just an opaque wrapper around a ByteArray.

Static methods

from_pem_file

Show source code
Hide 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 code
Hide source code
fn pub inline static new(bytes: ByteArray) -> PrivateKey {
  PrivateKey(bytes)
}
fn pub inline static new(bytes: ByteArray) -> PrivateKey

Returns a new PrivateKey that wraps the given ByteArray.

Instance methods

!=

Show source code
Hide source code
fn pub !=(other: ref Self) -> Bool {
  !(self == other)
}
fn pub !=(other: ref Self) -> Bool

Returns true if self and the given object are not equal to each other.

==

Show source code
Hide source code
fn pub ==(other: ref PrivateKey) -> Bool {
  @bytes == other.bytes
}
fn pub ==(other: ref PrivateKey) -> Bool

Returns 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 code
Hide 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

std.cmp.

Equal

impl Equal for PrivateKey
std.fmt.

Format

impl Format for PrivateKey