pub struct TransportCrypto { /* private fields */ }Expand description
Symmetric payload encryption (XChaCha20-Poly1305).
Implementations§
Source§impl TransportCrypto
impl TransportCrypto
Sourcepub fn from_bytes(key: [u8; 32]) -> TransportCrypto
pub fn from_bytes(key: [u8; 32]) -> TransportCrypto
Build from an explicit 32-byte key.
Callers own key material and secrecy. Prefer this in tests and when wiring a key from a secrets manager rather than the process environment.
Sourcepub fn from_env() -> Result<TransportCrypto, PhotonError>
pub fn from_env() -> Result<TransportCrypto, PhotonError>
Load key from PHOTON_TRANSPORT_KEY (standard base64 encoding of exactly 32 bytes).
§Errors
Returns PhotonError::Internal when the variable is missing, not valid
base64, or does not decode to 32 bytes. Production hosts should fail closed here.
§Contract
Does not fall back to a development key. Use Self::from_env_or_dev_default
only with an explicit development opt-in.
Sourcepub fn from_env_or_dev_default() -> Result<TransportCrypto, PhotonError>
pub fn from_env_or_dev_default() -> Result<TransportCrypto, PhotonError>
Load key from PHOTON_TRANSPORT_KEY, or the hard-coded development key when
explicitly opted in.
Development-only. The hard-coded key is used only when
PHOTON_ALLOW_DEV_TRANSPORT_KEY is 1 or true and PHOTON_TRANSPORT_KEY
is unset or invalid. A loud warning is printed when the development key is used.
Prefer Self::from_env in production and CI (set a real PHOTON_TRANSPORT_KEY).
§Errors
Returns an error when the environment key is missing/invalid and the development-key opt-in is not set.
Sourcepub fn encrypt(
&self,
actor_json: &Value,
payload_json: &Value,
) -> Result<Vec<u8>, PhotonError>
pub fn encrypt( &self, actor_json: &Value, payload_json: &Value, ) -> Result<Vec<u8>, PhotonError>
Encrypt actor + payload JSON into opaque ciphertext bytes.
§Errors
Returns an error if the operation fails.
Sourcepub fn seal_json_fields(
&self,
actor_json: &Value,
payload_json: &Value,
) -> Result<(Value, Value), PhotonError>
pub fn seal_json_fields( &self, actor_json: &Value, payload_json: &Value, ) -> Result<(Value, Value), PhotonError>
Seal actor and payload JSON for storage or transport.
The actor slot is replaced with null; the encrypted envelope is standard-base64 encoded
under ENVELOPE_JSON_KEY in the payload slot.
§Errors
Returns an error if JSON serialization or encryption fails.
Sourcepub fn open_json_fields(
&self,
actor_json: &Value,
payload_json: &Value,
) -> Result<(Value, Value), PhotonError>
pub fn open_json_fields( &self, actor_json: &Value, payload_json: &Value, ) -> Result<(Value, Value), PhotonError>
Open actor and payload JSON from a stored or wire event.
Unmarked fields are treated as legacy plaintext so existing persisted rows remain readable during migration.
§Errors
Returns an error if a marked envelope contains invalid base64 or cannot be decrypted.
Trait Implementations§
Source§impl Clone for TransportCrypto
impl Clone for TransportCrypto
Source§fn clone(&self) -> TransportCrypto
fn clone(&self) -> TransportCrypto
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more