Skip to main content

KeyStore

Struct KeyStore 

Source
pub struct KeyStore { /* private fields */ }
Expand description

Java KeyStore (JKS) implementation

A KeyStore is a mapping of alias to either a PrivateKeyEntry or TrustedCertificateEntry.

Implementations§

Source§

impl KeyStore

Source

pub fn load_pkcs12<R: Read>(&mut self, reader: R, password: &[u8]) -> Result<()>

Load a PKCS12 keystore from reader

PKCS12 is the standard keystore format used by:

  • Android (.keystore files)
  • Java (.p12/.pfx files)
  • OpenSSL
Source§

impl KeyStore

Source

pub fn new() -> Self

Creates a new empty KeyStore with default options

Source

pub fn with_options(options: KeyStoreOptions) -> Self

Creates a new empty KeyStore with custom options

Source

pub fn store<W: Write>(&self, w: W, password: &[u8]) -> Result<()>

Writes the keystore to the writer with password-based signature

It is strongly recommended to zero out the password after use.

Source

pub fn load<R: Read>(&mut self, r: R, password: &[u8]) -> Result<()>

Reads a keystore from the reader and verifies its signature

It is strongly recommended to zero out the password after use.

Source

pub fn load_auto_detect<R: Read>( &mut self, reader: R, password: &[u8], ) -> Result<()>

Auto-detect format and load keystore from reader

This method automatically detects whether the file is JKS or PKCS12 format and loads it accordingly. Supports:

  • JKS format (.jks files) - magic: 0xFEEDFEED
  • PKCS12 format (.keystore, .p12, .pfx files) - starts with 0x30

It is strongly recommended to zero out the password after use.

Source

pub fn set_private_key_entry( &mut self, alias: &str, entry: PrivateKeyEntry, password: &[u8], ) -> Result<()>

Adds a PrivateKeyEntry encrypted with the password

It is strongly recommended to zero out the password after use.

Source

pub fn get_private_key_entry( &self, alias: &str, password: &[u8], ) -> Result<PrivateKeyEntry>

Returns and decrypts a PrivateKeyEntry with the password

It is strongly recommended to zero out the password after use.

Source

pub fn get_raw_private_key_entry(&self, alias: &str) -> Result<PrivateKeyEntry>

Returns a PrivateKeyEntry without decryption (for already-decrypted keys like PKCS12)

This method returns the private key entry as-is, without attempting to decrypt it. Useful for keystores loaded from PKCS12 format where keys are already decrypted.

Source

pub fn get_private_key_entry_certificate_chain( &self, alias: &str, ) -> Result<Vec<Certificate>>

Returns the certificate chain associated with a PrivateKeyEntry

Source

pub fn is_private_key_entry(&self, alias: &str) -> bool

Returns true if the alias exists and is a PrivateKeyEntry

Source

pub fn set_trusted_certificate_entry( &mut self, alias: &str, entry: TrustedCertificateEntry, ) -> Result<()>

Adds a TrustedCertificateEntry (not encrypted, just stored)

Source

pub fn get_trusted_certificate_entry( &self, alias: &str, ) -> Result<TrustedCertificateEntry>

Returns a TrustedCertificateEntry

Source

pub fn is_trusted_certificate_entry(&self, alias: &str) -> bool

Returns true if the alias exists and is a TrustedCertificateEntry

Source

pub fn delete_entry(&mut self, alias: &str)

Deletes an entry from the keystore

Source

pub fn aliases(&self) -> Vec<String>

Returns all aliases in the keystore

If ordered_aliases is set, returns aliases sorted alphabetically.

Source

pub fn len(&self) -> usize

Returns the number of entries in the keystore

Source

pub fn is_empty(&self) -> bool

Returns true if the keystore is empty

Trait Implementations§

Source§

impl Default for KeyStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V