Error Handling
Exception table
| Exception | When raised |
|---|---|
synta.SyntaError | ASN.1 parse or encode failure (wraps the Rust synta::Error) |
synta.x509.X509VerificationError | Certificate chain verification failure (see synta.x509) |
ValueError | Invalid arguments (e.g. invalid OID string, bad charset for PrintableString, wrong password format) |
OverflowError | Integer.to_int() / to_i128() when the value does not fit |
EOFError | Decoder.peek_tag() / decode_* when no data remains |
ImportError | Certificate.to_pyca() / from_pyca() when cryptography is not installed |
Example
import synta
try:
# Invalid OID (first component must be 0, 1, or 2)
oid = synta.ObjectIdentifier("5.2.840")
except ValueError as e:
print(f"Error: {e}")
try:
# Truncated data
decoder = synta.Decoder(b'\x02\x05', synta.Encoding.DER)
integer = decoder.decode_integer()
except EOFError as e:
print(f"Unexpected end of data: {e}")
try:
# Invalid DER
decoder = synta.Decoder(b'\xff\xff', synta.Encoding.DER)
obj = decoder.decode_any()
except synta.SyntaError as e:
print(f"Parse error: {e}")
Error mapping
SyntaErr (the internal Rust error type) is mapped to Python exceptions as
follows:
- EOF / truncated data →
EOFError - Integer overflow →
OverflowError - Any other ASN.1 parse error →
ValueErrororsynta.SyntaError
The SyntaError exception class is a subclass of Exception.