Module Expr Str Import alias Import alias Import alias ImportFrom alias ImportFrom alias ImportFrom alias Import alias ImportFrom alias ImportFrom alias alias ImportFrom alias ImportFrom alias alias ImportFrom alias ClassDef bases NameLoad body Pass decorator_list Assign NameStore Call NameLoad Str TupleLoad Str Str Str Str FunctionDef arguments args NameParam NameParam defaults body Expr Str TryExcept body ImportFrom alias Return Call NameLoad NameLoad NameLoad handlers ExceptHandler type NameLoad body Pass If CompareNotEq Call NameLoad NameLoad Call NameLoad NameLoad body Assign NameStore Num Assign NameStore Call NameLoad NameLoad Assign NameStore Call NameLoad NameLoad orelse Assign NameStore Num Assign NameStore Call NameLoad NameLoad Assign NameStore Call NameLoad NameLoad For TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad body AugAssignBitOr NameStore BinOpBitXor NameLoad NameLoad Return CompareEq NameLoad Num decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return Call NameLoad NameLoad BinOpMult Str Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults Num body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Num keyword NameLoad Return Call AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr keyword NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad keyword NameLoad keyword AttributeLoad NameLoad attr Return Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str Assert BoolOpAnd CompareGtE Call NameLoad NameLoad Num CompareEq Call NameLoad NameLoad Num Assign NameStore Num Assign NameStore Num Return BinOpAdd BinOpAdd SubscriptLoad NameLoad Slice NameLoad NameLoad SubscriptLoad NameLoad Slice NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Expr Str Assert CompareEq AttributeLoad AttributeLoad NameLoad attr attr NameLoad Expr Call AttributeLoad AttributeLoad SubscriptLoad NameLoad Index Num attr attr Call AttributeLoad NameLoad attr Assign AttributeStore AttributeLoad NameLoad attr attr SubscriptLoad Call AttributeLoad AttributeLoad SubscriptLoad NameLoad Index Num attr attr Slice Num Assign NameStore Call AttributeLoad NameLoad attr For NameStore Call NameLoad NameLoad body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Return Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr NameLoad keyword NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str If BoolOpOr CompareLt Call NameLoad NameLoad Num CompareNotEq SubscriptLoad NameLoad Slice Num Num NameLoad body Return NameLoad Assign NameStore SubscriptLoad NameLoad Slice Num Num Assign NameStore Call NameLoad NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr NameLoad Return CompareEq SubscriptLoad Call AttributeLoad NameLoad attr Slice Num NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Num Assign NameStore NameLoad Assign NameStore Call AttributeLoad NameLoad attr For NameStore NameLoad body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad If Call NameLoad NameLoad NameLoad body Assign NameStore NameLoad Break AugAssignAdd NameStore Num If UnaryOpNot NameLoad body Raise Call NameLoad Assign NameStore Call NameLoad NameLoad Expr Call AttributeLoad AttributeLoad SubscriptLoad NameLoad Index NameLoad attr attr NameLoad If CompareLt AttributeLoad AttributeLoad NameLoad attr attr Num body Assign NameStore Call AttributeLoad NameLoad attr Str AttributeLoad AttributeLoad NameLoad attr attr orelse Assign NameStore Call AttributeLoad NameLoad attr Str AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Call AttributeLoad NameLoad attr Str AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Call AttributeLoad NameLoad attr BinOpAdd BinOpAdd NameLoad NameLoad NameLoad Return TupleLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Str body Expr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore SubscriptLoad NameLoad Index Num Assign NameStore SubscriptLoad NameLoad Index Num Assign NameStore SubscriptLoad NameLoad Index Num Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore AttributeLoad NameLoad attr If CompareNotEq SubscriptLoad NameLoad Index Num Str body Return NameLoad Assign NameStore SubscriptLoad NameLoad Slice Num TryExcept body Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad NameLoad NameLoad Return NameLoad handlers ExceptHandler type AttributeLoad AttributeLoad NameLoad attr attr body Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr TryExcept body Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Str Return CompareLtLt NameLoad NameLoad NameLoad handlers ExceptHandler type NameLoad body Return NameLoad decorator_list
N/A N/A 
.. topic:: Details

    Crypto utility functions. Includes:

        - Constant time string comparisons
        - Wrappers around encryption/decryption operations
        - The "recognized" check for incoming cells
        - A couple methods for verifying TLS certificate properties (signatures
          and times)

 N/A hashlib N/A hmac N/A struct collections namedtuple datetime datetime itertools izip N/A OpenSSL Crypto.Cipher AES Crypto.Util asn1 Counter oppy.cell.cell Cell oppy.cell.definitions RECOGNIZED EMPTY_DIGEST oppy.cell.fixedlen EncryptedCell UnrecognizedCell N/A Exception N/A N/A N/A N/A RelayCrypto N/A namedtuple RelayCrypto N/A forward_digest backward_digest forward_cipher backward_cipher constantStrEqual N/A N/A str1 str2 N/A N/A N/A Do a constant-time comparison of str1 and str2, returning **True**
    if they are equal, **False** otherwise.

    :param str str1: first string to compare
    :param str str2: second string to compare
    :returns: **bool** **True** if str1 == str2, **False** otherwise
     N/A N/A hmac compare_digest N/A N/A compare_digest str1 str2 N/A N/A N/A ImportError N/A N/A N/A N/A N/A len str1 N/A len str2 N/A N/A res 1 N/A comp1 N/A bytearray str2 N/A comp2 N/A bytearray str2 N/A N/A res 0 N/A comp1 N/A bytearray str1 N/A comp2 N/A bytearray str2 N/A N/A a b N/A izip comp1 comp2 N/A N/A res N/A a b N/A N/A res 0 N/A constantStrAllZero N/A N/A s N/A N/A N/A Check if *s* consists of all zero bytes.

    :param str s: string to check
    :returns: **bool** **True** if *s* contains all zero bytes, **False**
        otherwise
     N/A N/A constantStrEqual s N/A N/A len s N/A makeAES128CTRCipher N/A N/A key initial_value N/A 0 N/A N/A Create and return a new AES128-CTR cipher instance.

    :param str key: key to use for this cipher
    :param initial_value: initial_value to use
    :returns: **Crypto.Cipher.AES.AES**
     N/A ctr N/A N/A Counter new 128 initial_value initial_value N/A N/A N/A AES new key N/A AES MODE_CTR counter ctr N/A makeHMACSHA256 N/A N/A msg key N/A N/A N/A Make a new HMAC-SHA256 with *msg* and *key* and return digest byte
    string.

    :param str msg: msg
    :param str key: key to use
    :returns: **str** HMAC digest
     N/A t N/A N/A hmac new msg msg key key digestmod N/A hashlib sha256 N/A N/A N/A t digest N/A _makePayloadWithDigest N/A N/A payload digest N/A EMPTY_DIGEST N/A N/A Make a new payload with *digest* inserted in the correct position.

    :param str payload: payload in which to insert digest
    :param str digest: digest to insert
    :returns: **str** payload with digest inserted into correct position
     N/A N/A N/A N/A len payload 9 N/A N/A len digest 4 N/A DIGEST_START 5 N/A DIGEST_END 9 N/A N/A N/A N/A payload N/A DIGEST_START digest N/A payload N/A DIGEST_END N/A encryptCell N/A N/A cell crypt_path early N/A False N/A N/A Encrypt *cell* to the *target* relay in *crypt_path* and update
    the appropriate forward digest.

    :param cell cell: cell to encrypt
    :param list crypt_path: list of RelayCrypto instances available for
        encryption
    :param int target: target node to encrypt to
    :param bool early: if **True**, use a RELAY_EARLY cmd instead of a
        RELAY cmd
    :returns: **oppy.cell.fixedlen.EncryptedCell**
     N/A N/A N/A N/A cell rheader digest EMPTY_DIGEST N/A N/A N/A N/A N/A crypt_path N/A -1 forward_digest update N/A N/A cell getPayload N/A N/A N/A cell rheader digest N/A N/A N/A N/A N/A crypt_path N/A -1 forward_digest digest N/A 4 N/A payload N/A N/A cell getPayload N/A node N/A reversed crypt_path N/A N/A payload N/A N/A N/A node forward_cipher encrypt payload N/A N/A N/A EncryptedCell make N/A N/A cell header circ_id payload early early N/A _cellRecognized N/A N/A payload relay_crypto N/A N/A N/A Return **True** if this payload is *recognized*.

    .. note:: See tor-spec Section 6.1 for details about what it means for a
        cell to be *recognized*.

    :param str payload: payload to check if recognized
    :param oppy.crypto.relaycrypto.RelayCrypto relay_crypto: RelayCrypto
        instance to use for checking if payload is recognized
    :returns: **bool** **True** if this payload is recognized, **False**
        otherwise
     N/A N/A N/A N/A len payload 9 N/A N/A payload N/A 2 4 RECOGNIZED N/A N/A False N/A digest N/A payload N/A 5 9 N/A test_payload N/A _makePayloadWithDigest payload N/A test_digest N/A N/A N/A relay_crypto backward_digest copy N/A N/A N/A test_digest update test_payload N/A N/A N/A N/A N/A test_digest digest N/A 4 digest N/A decryptCell N/A N/A cell crypt_path N/A N/A N/A Decrypt *cell* until it is recognized or we've tried all RelayCrypto's
    in *crypt_path*.

    Attempt to decrypt the cell one hop at a time. Stop if the cell is
    recognized. Raise an exception if the cell is not recognized at all.

    :param cell cell: cell to decrypt
    :param list, oppy.crypto.relaycrypto.RelayCrypto crypt_path: list of
        RelayCrypto instances to use for decryption
    :param int origin: the originating hop we think this cell came from
    :returns: the concrete RelayCell type of this decrypted cell
     N/A origin 0 N/A recognized False N/A payload N/A N/A cell getPayload N/A node crypt_path N/A N/A payload N/A N/A N/A node backward_cipher decrypt payload N/A N/A _cellRecognized payload node N/A N/A recognized True N/A N/A origin 1 N/A N/A recognized N/A N/A N/A UnrecognizedCell N/A updated_payload N/A _makePayloadWithDigest payload N/A N/A N/A N/A N/A crypt_path N/A origin backward_digest update updated_payload N/A N/A N/A N/A cell header link_version 4 N/A N/A cid N/A N/A struct pack !H N/A N/A cell header circ_id N/A N/A cid N/A N/A struct pack !I N/A N/A cell header circ_id N/A cmd N/A N/A struct pack !B N/A N/A cell header cmd N/A dec N/A N/A Cell parse N/A N/A cid cmd payload N/A N/A dec origin N/A verifyCertSig N/A N/A id_cert cert_to_verify algo N/A sha1 N/A N/A Verify that the SSL certificate *id_cert* has signed the TLS cert
    *cert_to_verify*.

    :param id_cert: Identification Certificate
    :type id_cert: OpenSSL.crypto.X509
    :param cert_to_verify: certificate to verify signature on
    :type cert_to_verify: OpenSSL.crypto.X509
    :param algo: algorithm to use for certificate verification
    :type algo: str

    :returns: **bool** **True** if the signature of *cert_to_verify* can be
        verified from *id_cert*, **False** otherwise
     N/A cert_to_verify_ASN1 N/A N/A N/A OpenSSL crypto dump_certificate N/A N/A OpenSSL crypto FILETYPE_ASN1 cert_to_verify N/A der N/A N/A asn1 DerSequence N/A N/A N/A der decode cert_to_verify_ASN1 N/A cert_to_verify_DER N/A der N/A 0 N/A cert_to_verify_ALGO N/A der N/A 1 N/A cert_to_verify_SIG N/A der N/A 2 N/A sig_DER N/A N/A asn1 DerObject N/A N/A N/A sig_DER decode cert_to_verify_SIG N/A sig N/A sig_DER payload N/A N/A N/A sig N/A 0 N/A N/A False N/A sig N/A sig N/A 1 N/A N/A N/A N/A N/A N/A OpenSSL crypto verify id_cert sig cert_to_verify_DER algo N/A True N/A N/A N/A N/A N/A OpenSSL crypto Error N/A N/A False N/A validCertTime N/A N/A cert N/A N/A N/A Verify that TLS certificate *cert*'s time is not earlier than
    cert.notBefore and not later than cert.notAfter.

    :param OpenSSL.crypto.X509 cert: TLS Certificate to verify times of
    :returns: **bool** **True** if cert.notBefore < now < cert.notAfter,
        **False** otherwise
     N/A now N/A N/A datetime now N/A N/A N/A validAfter N/A N/A datetime strptime N/A N/A cert get_notBefore %Y%m%d%H%M%SZ N/A validUntil N/A N/A datetime strptime N/A N/A cert get_notAfter %Y%m%d%H%M%SZ N/A N/A validAfter now validUntil N/A N/A N/A ValueError N/A N/A False N/A