Transformers¶
This page describe internal utility classes use to parse or help with converting data from Tor to python structures. Most of these classes rely on pydantic to handle the heavy lifting.
- class aiostem.utils.transformers.TrAfterAsTimezone[source]¶
Post-validator that enforces a timezone.
- class aiostem.utils.transformers.TrBeforeSetToNone[source]¶
Pre-validator that sets a value to
None.
- class aiostem.utils.transformers.TrBeforeStringSplit[source]¶
Deserialize sequences from/to strings.
-
model_config:
ClassVar[ConfigDict|None] = None¶ Base pydantic configuration to apply when serializing.
-
model_config:
- class aiostem.utils.transformers.TrBeforeTimedelta[source]¶
Pre-validator that gets a timedelta from an int or float.
- class aiostem.utils.transformers.TrEd25519PrivateKey[source]¶
Transform bytes into an ed25519 private key.
Note
Tor’s implementation of Ed25519 is donna-ed25519 and uses the expanded form as the private key (64 bytes). Unfortunately
cryptographydoes not provide such interface, which means that we are left with this implementation.-
expanded:
bool¶ Whether to generate the expanded form while serializing.
Note
This makes parsing impossible…
- from_bytes(data: bytes) Ed25519PrivateKey[source]¶
Build an ed25519 private key out of the provided bytes.
- Parameters:
data (
bytes) – a 32 bytes seed representing a secret key.- Returns:
Ed25519PrivateKey– An instance of an ed25519 private key.
- to_bytes(key: Ed25519PrivateKey) bytes[source]¶
Serialize the provided private key to bytes.
See also
- Returns:
bytes– 32 or 64 bytes corresponding to the private key.
- to_expanded_bytes(key: Ed25519PrivateKey) bytes[source]¶
Serialize to the expanded form.
- Returns:
bytes– 64 bytes corresponding to the expanded private key.
- to_seed_bytes(key: Ed25519PrivateKey) bytes[source]¶
Serialize the seed bytes, which is the default behavior.
- Returns:
bytes– 32 bytes corresponding to the private key.
-
expanded:
- class aiostem.utils.transformers.TrEd25519PublicKey[source]¶
Transform bytes into a ed25519 public key.
- from_bytes(data: bytes) Ed25519PublicKey[source]¶
Build an ed25519 public key out of the provided bytes.
- Returns:
Ed25519PublicKey– An instance of an ed25519 public key.
- to_bytes(key: Ed25519PublicKey) bytes[source]¶
Serialize the provided public key to bytes.
- Returns:
bytes– 32 bytes corresponding to the public key.
- class aiostem.utils.transformers.TrRSAPrivateKey[source]¶
Transform bytes into a RSA private key.
-
format:
PrivateFormat¶ Key format used while serializing.
- from_bytes(data: bytes) RSAPrivateKey[source]¶
Build a RSA private key out of the provided bytes.
- Returns:
RSAPrivateKey– An instance of a RSA private key.
- to_bytes(key: RSAPrivateKey) bytes[source]¶
Serialize the provided private key to bytes.
- Return type:
-
format:
- class aiostem.utils.transformers.TrRSAPublicKey[source]¶
Transform bytes into a RSA public key.
-
format:
PublicFormat¶ Key format used while serializing.
- from_bytes(data: bytes) RSAPublicKey[source]¶
Build a RSA public key out of the provided bytes.
- Returns:
RSAPublicKey– An instance of a RSA public key.
- to_bytes(key: RSAPublicKey) bytes[source]¶
Serialize the provided public key to bytes.
- Return type:
-
format:
- class aiostem.utils.transformers.TrX25519PrivateKey[source]¶
Transform bytes into a X25519 private key.
- from_bytes(data: bytes) X25519PrivateKey[source]¶
Build a X25519 private key out of the provided bytes.
- Returns:
X25519PrivateKey– An instance of a X25519 private key.
- to_bytes(key: X25519PrivateKey) bytes[source]¶
Serialize the provided private key to bytes.
- Returns:
bytes– 32 bytes corresponding to the private key.
- class aiostem.utils.transformers.TrX25519PublicKey[source]¶
Transform bytes into a X25519 public key.
- from_bytes(data: bytes) X25519PublicKey[source]¶
Build a X25519 public key out of the provided bytes.
- Returns:
X25519PublicKey– An instance of a X25519 public key.
- to_bytes(key: X25519PublicKey) bytes[source]¶
Serialize the provided public key to bytes.
- Returns:
bytes– 32 bytes corresponding to the public key.