Why a PKCS#12 file could not be read or written.
PKCS12.decode/3 and PKCS12.encode/3 return it as
{:error, %PKCS12.Error{}}, and PKCS12.decode!/3 and PKCS12.encode!/3
raise it. Match on :reason:
:malformed- not a valid PKCS#12 structure.:invalid_password- the MAC does not match, or, in a file without a MAC, the content does not decrypt.{:unsupported_version, version}- the PFX version is not 3.{:unsupported_algorithm, oid}- an algorithm the library does not implement, with its OID in dotted form.{:unsupported, :public_key_integrity | :public_key_privacy}- the file is signed with, or encrypted to, a public key instead of a password. Such files are very rare.{:not_available, algorithm}- the library knows the algorithm, but the:cryptoapplication of this system (its OpenSSL) refuses it. For example, RC4 when the OpenSSL "legacy" provider is missing, or parameters that a FIPS provider rejects.{:too_many_iterations, count}- one key derivation asks for more iterations than the:max_iterationsoption allows.{:too_many_total_iterations, count}- the work of all derivations together goes beyond the:max_total_iterationsoption;countis the work done or due when the limit was reached.{:unsupported_mac_key_size, bytes}- a PBMAC1 key size outside 20..64 bytes.{:invalid_input, field}- when writing,field(:private_key,:certificateor:ca_certificates) is not a key or certificates in a form thatPKCS12.encode/3takes.
The error never carries the password or any key material.
Summary
Types
@type reason() :: :malformed | :invalid_password | {:unsupported_version, non_neg_integer()} | {:unsupported_algorithm, String.t()} | {:unsupported, :public_key_integrity | :public_key_privacy} | {:not_available, atom()} | {:too_many_iterations, pos_integer()} | {:too_many_total_iterations, pos_integer()} | {:unsupported_mac_key_size, non_neg_integer()} | {:invalid_input, :private_key | :certificate | :ca_certificates}
@type t() :: %PKCS12.Error{__exception__: true, reason: reason()}