Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error Handling

Exception table

ExceptionWhen raised
synta.SyntaErrorASN.1 parse or encode failure (wraps the Rust synta::Error)
synta.x509.X509VerificationErrorCertificate chain verification failure (see synta.x509)
ValueErrorInvalid arguments (e.g. invalid OID string, bad charset for PrintableString, wrong password format)
OverflowErrorInteger.to_int() / to_i128() when the value does not fit
EOFErrorDecoder.peek_tag() / decode_* when no data remains
ImportErrorCertificate.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 → ValueError or synta.SyntaError

The SyntaError exception class is a subclass of Exception.