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 moreAuto Trait Implementations§
impl Freeze for TransportCrypto
impl RefUnwindSafe for TransportCrypto
impl Send for TransportCrypto
impl Sync for TransportCrypto
impl Unpin for TransportCrypto
impl UnsafeUnpin for TransportCrypto
impl UnwindSafe for TransportCrypto
Blanket Implementations§
impl<T> AsyncConnector for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more