def __init__(self, proto, spi, seq_num=1, crypt_algo=None, crypt_key=None,
                 auth_algo=None, auth_key=None, tunnel_header=None, nat_t_header=None):  # noqa: E501
        """
        @param proto: the IPsec proto to use (ESP or AH)
        @param spi: the Security Parameters Index of this SA
        @param seq_num: the initial value for the sequence number on encrypted
                        packets
        @param crypt_algo: the encryption algorithm name (only used with ESP)
        @param crypt_key: the encryption key (only used with ESP)
        @param auth_algo: the integrity algorithm name
        @param auth_key: the integrity key
        @param tunnel_header: an instance of a IP(v6) header that will be used
                              to encapsulate the encrypted packets.
        @param nat_t_header: an instance of a UDP header that will be used
                             for NAT-Traversal.
        """

        if proto not in (ESP, AH, ESP.name, AH.name):
            raise ValueError("proto must be either ESP or AH")
        if isinstance(proto, six.string_types):
            self.proto = eval(proto)
        else:
            self.proto = proto

        self.spi = spi
        self.seq_num = seq_num

        if crypt_algo:
            if crypt_algo not in CRYPT_ALGOS:
                raise TypeError('unsupported encryption algo %r, try %r' %
                                (crypt_algo, list(CRYPT_ALGOS)))
            self.crypt_algo = CRYPT_ALGOS[crypt_algo]

            if crypt_key:
                salt_size = self.crypt_algo.salt_size
                self.crypt_key = crypt_key[:len(crypt_key) - salt_size]
                self.crypt_salt = crypt_key[len(crypt_key) - salt_size:]
            else:
                self.crypt_key = None
                self.crypt_salt = None

        else:
            self.crypt_algo = CRYPT_ALGOS['NULL']
            self.crypt_key = None

        if auth_algo:
            if auth_algo not in AUTH_ALGOS:
                raise TypeError('unsupported integrity algo %r, try %r' %
                                (auth_algo, list(AUTH_ALGOS)))
            self.auth_algo = AUTH_ALGOS[auth_algo]
            self.auth_key = auth_key
        else:
            self.auth_algo = AUTH_ALGOS['NULL']
            self.auth_key = None

        if tunnel_header and not isinstance(tunnel_header, (IP, IPv6)):
            raise TypeError('tunnel_header must be %s or %s' % (IP.name, IPv6.name))  # noqa: E501
        self.tunnel_header = tunnel_header

        if nat_t_header:
            if proto is not ESP:
                raise TypeError('nat_t_header is only allowed with ESP')
            if not isinstance(nat_t_header, UDP):
                raise TypeError('nat_t_header must be %s' % UDP.name)
        self.nat_t_header = nat_t_header
def __init__ ( self , proto , spi , seq_num = 1 , crypt_algo = None , crypt_key = None , auth_algo = None , auth_key = None , tunnel_header = None , nat_t_header = None ) : if proto not in ( ESP , AH , ESP . name , AH . name ) : raise ValueError ( "proto must be either ESP or AH" ) if isinstance ( proto , six . string_types ) : self . proto = eval ( proto ) else : self . proto = proto self . spi = spi self . seq_num = seq_num if crypt_algo : if crypt_algo not in CRYPT_ALGOS : raise TypeError ( 'unsupported encryption algo %r, try %r' % ( crypt_algo , list ( CRYPT_ALGOS ) ) ) self . crypt_algo = CRYPT_ALGOS [ crypt_algo ] if crypt_key : salt_size = self . crypt_algo . salt_size self . crypt_key = crypt_key [ : len ( crypt_key ) - salt_size ] self . crypt_salt = crypt_key [ len ( crypt_key ) - salt_size : ] else : self . crypt_key = None self . crypt_salt = None else : self . crypt_algo = CRYPT_ALGOS [ 'NULL' ] self . crypt_key = None if auth_algo : if auth_algo not in AUTH_ALGOS : raise TypeError ( 'unsupported integrity algo %r, try %r' % ( auth_algo , list ( AUTH_ALGOS ) ) ) self . auth_algo = AUTH_ALGOS [ auth_algo ] self . auth_key = auth_key else : self . auth_algo = AUTH_ALGOS [ 'NULL' ] self . auth_key = None if tunnel_header and not isinstance ( tunnel_header , ( IP , IPv6 ) ) : raise TypeError ( 'tunnel_header must be %s or %s' % ( IP . name , IPv6 . name ) ) self . tunnel_header = tunnel_header if nat_t_header : if proto is not ESP : raise TypeError ( 'nat_t_header is only allowed with ESP' ) if not isinstance ( nat_t_header , UDP ) : raise TypeError ( 'nat_t_header must be %s' % UDP . name ) self . nat_t_header = nat_t_header
@param proto: the IPsec proto to use (ESP or AH)
        @param spi: the Security Parameters Index of this SA
        @param seq_num: the initial value for the sequence number on encrypted
                        packets
        @param crypt_algo: the encryption algorithm name (only used with ESP)
        @param crypt_key: the encryption key (only used with ESP)
        @param auth_algo: the integrity algorithm name
        @param auth_key: the integrity key
        @param tunnel_header: an instance of a IP(v6) header that will be used
                              to encapsulate the encrypted packets.
        @param nat_t_header: an instance of a UDP header that will be used
                             for NAT-Traversal.