o
    B]G                     @   s   d dl mZ d dlmZ d dlmZ g dZG dd deZej	Z		 ej
Z
	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 ejZ	 G dd deZd	S )
    )config)error)null)CommunityDataUsmUserDatausm3DESEDEPrivProtocolusmAesCfb128ProtocolusmAesCfb192ProtocolusmAesCfb256ProtocolusmAesBlumenthalCfb192ProtocolusmAesBlumenthalCfb256ProtocolusmDESPrivProtocolusmHMACMD5AuthProtocolusmHMACSHAAuthProtocolusmHMAC128SHA224AuthProtocolusmHMAC192SHA256AuthProtocolusmHMAC256SHA384AuthProtocolusmHMAC384SHA512AuthProtocolusmNoAuthProtocolusmNoPrivProtocolc                   @   sX   e Zd ZdZdZed ZdZeZeZ				dddZ
dd Zd	d
 Z			dddZdS )r   a  Creates SNMP v1/v2c configuration entry.

    This object can be used by
    :py:class:`~pysnmp.hlapi.asyncore.AsyncCommandGenerator` or
    :py:class:`~pysnmp.hlapi.asyncore.AsyncNotificationOriginator`
    and their derivatives for adding new entries to Local Configuration
    Datastore (LCD) managed by :py:class:`~pysnmp.hlapi.SnmpEngine`
    class instance.

    See :RFC:`2576#section-5.3` for more information on the
    *SNMP-COMMUNITY-MIB::snmpCommunityTable*.

    Parameters
    ----------
    communityIndex: :py:class:`str`, :py:class:`~pysnmp.proto.rfc1902.OctetString`
        Unique index value of a row in snmpCommunityTable. If it is the
        only positional parameter, it is treated as a *communityName*.

    communityName: :py:class:`str`, :py:class:`~pysnmp.proto.rfc1902.OctetString`
        SNMP v1/v2c community string.

    mpModel: :py:class:`int`
        SNMP message processing model AKA SNMP version. Known SNMP versions are:

        * `0` - for SNMP v1
        * `1` - for SNMP v2c (default)


    contextEngineId: :py:class:`str`, :py:class:`~pysnmp.proto.rfc1902.OctetString`
        Indicates the location of the context in which management
        information is accessed when using the community string
        specified by the above communityName.

    contextName: :py:class:`str`, :py:class:`~pysnmp.proto.rfc1902.OctetString`
        The context in which management information is accessed when
        using the above communityName.

    tag: :py:class:`str`
        Arbitrary string that specifies a set of transport endpoints
        from which a command responder application will accept
        management requests with given *communityName* or to which
        notification originator application will send notifications
        when targets are specified by a tag value(s).

        The other way to look at the *tag* feature is that it can make
        specific *communityName* only valid for certain targets.

        The other use-case is when multiple distinct SNMP peers share
        the same *communityName* -- binding each instance of
        *communityName* to transport endpoint lets you distinguish
        SNMP peers from each other (e.g. resolving *communityName* into
        proper *securityName*).

        For more technical information on SNMP configuration tags please
        refer to :RFC:`3413#section-4.1.1` and :RFC:`2576#section-5.3`
        (e.g. the *snmpCommunityTransportTag* object).

        See also: :py:class:`~pysnmp.hlapi.UdpTransportTarget`

    Warnings
    --------
    If the same *communityIndex* value is supplied repeatedly with
    different *communityName* (or other parameters), the later call
    supersedes all previous calls.

    Make sure not to configure duplicate *communityName* values unless
    they have distinct *mpModel* and/or *tag* fields. This will make
    *communityName* based database lookup ambiguous.

    Examples
    --------
    >>> from pysnmp.hlapi import CommunityData
    >>> CommunityData('public')
    CommunityData(communityIndex='s1410706889', communityName=<COMMUNITY>, mpModel=1, contextEngineId=None, contextName='', tag='')
    >>> CommunityData('public', 'public')
    CommunityData(communityIndex='public', communityName=<COMMUNITY>, mpModel=1, contextEngineId=None, contextName='', tag='')
    >>>

       noAuthNoPrivNc                 C   s   |d ur|| _ |d | _|| _|d ur|| _|d ur|| _|d u r&|d }}|| _|d u rCdt| j| j | j| j| jf  | _| _d S || _|d urL|pM|| _d S )Nr   zs%s)	mpModelsecurityModelcontextEngineIdcontextNametagcommunityNamehashcommunityIndexsecurityNameselfr   r   r   r   r   r   r     r#   3/usr/lib/python3/dist-packages/pysnmp/hlapi/auth.py__init__l   s&   

zCommunityData.__init__c                 C      t d| jj Nz%s is not hashable	TypeError	__class____name__r"   r#   r#   r$   __hash__      zCommunityData.__hash__c                 C   s&   d| j j| j| j| j| j| j| jf S )Nzy%s(communityIndex=%r, communityName=<COMMUNITY>, mpModel=%r, contextEngineId=%r, contextName=%r, tag=%r, securityName=%r))r*   r+   r   r   r   r   r   r    r,   r#   r#   r$   __repr__   s   zCommunityData.__repr__c              
   C   s|   |d u r	|d }}|  ||d u r| jp||d u r| jp||d u r#| jp$||d u r+| jp,||d u r3| jp4||d u r;| jp<|S N)r*   r   r   r   r   r   r    r!   r#   r#   r$   clone   s   
zCommunityData.clone)NNNNNN)NNNNNNN)r+   
__module____qualname____doc__r   r   securityLevelr   r   r   r%   r-   r/   r1   r#   r#   r#   r$   r      s"    O
r   c                   @   sr   e Zd ZdZd ZZejZej	Z
dZdZdZeZddddddeefddZdd Zd	d
 Z					dddZdS )r   a  Creates SNMP v3 User Security Model (USM) configuration entry.

    This object can be used by
    :py:class:`~pysnmp.hlapi.asyncore.AsyncCommandGenerator` or
    :py:class:`~pysnmp.hlapi.asyncore.AsyncNotificationOriginator`
    and their derivatives for adding new entries to Local Configuration
    Datastore (LCD) managed by :py:class:`~pysnmp.hlapi.SnmpEngine`
    class instance.

    See :RFC:`3414#section-5` for more information on the
    *SNMP-USER-BASED-SM-MIB::usmUserTable*.

    Parameters
    ----------
    userName: :py:class:`str`, :py:class:`~pysnmp.proto.rfc1902.OctetString`
        A human readable string representing the name of the SNMP USM user.

    Other Parameters
    ----------------
    authKey: :py:class:`str`, :py:class:`~pysnmp.proto.rfc1902.OctetString`
        Initial value of the secret authentication key.  If not set,
        :py:class:`~pysnmp.hlapi.usmNoAuthProtocol`
        is implied.  If set and no *authProtocol* is specified,
        :py:class:`~pysnmp.hlapi.usmHMACMD5AuthProtocol`
        takes effect.

    privKey: :py:class:`str`, :py:class:`~pysnmp.proto.rfc1902.OctetString`
        Initial value of the secret encryption key.  If not set,
        :py:class:`~pysnmp.hlapi.usmNoPrivProtocol`
        is implied.  If set and no *privProtocol* is specified,
        :py:class:`~pysnmp.hlapi.usmDESPrivProtocol`
        takes effect.

    authProtocol: :py:class:`tuple`, :py:class:`~pysnmp.proto.rfc1902.ObjectIdentifier`
        An indication of whether messages sent on behalf of this USM user
        can be authenticated, and if so, the type of authentication protocol
        which is used.

        Supported authentication protocol identifiers are:

        * :py:class:`~pysnmp.hlapi.usmNoAuthProtocol` (default is *authKey* not given)
        * :py:class:`~pysnmp.hlapi.usmHMACMD5AuthProtocol` (default if *authKey* is given)
        * :py:class:`~pysnmp.hlapi.usmHMACSHAAuthProtocol`
        * :py:class:`~pysnmp.hlapi.usmHMAC128SHA224AuthProtocol`
        * :py:class:`~pysnmp.hlapi.usmHMAC192SHA256AuthProtocol`
        * :py:class:`~pysnmp.hlapi.usmHMAC256SHA384AuthProtocol`
        * :py:class:`~pysnmp.hlapi.usmHMAC384SHA512AuthProtocol`


    securityEngineId: :py:class:`~pysnmp.proto.rfc1902.OctetString`
        The snmpEngineID of the authoritative SNMP engine to which a
        dateRequest message is to be sent. Will be automatically
        discovered from peer if not given, unless localized keys
        are used. In the latter case *securityEngineId* must be
        specified.

        See :RFC:`3414#section-2.5.1` for technical explanation.

    securityName: :py:class:`str`, :py:class:`~pysnmp.proto.rfc1902.OctetString`
        Together with the snmpEngineID it identifies a row in the
        *SNMP-USER-BASED-SM-MIB::usmUserTable* that is to be used
        for securing the message.

        See :RFC:`3414#section-2.5.1` for technical explanation.

    privProtocol: :py:class:`tuple`, :py:class:`~pysnmp.proto.rfc1902.ObjectIdentifier`
        An indication of whether messages sent on behalf of this USM user
        be encrypted, and if so, the type of encryption protocol which is used.

        Supported encryption protocol identifiers are:

        * :py:class:`~pysnmp.hlapi.usmNoPrivProtocol` (default is *authKey* not given)
        * :py:class:`~pysnmp.hlapi.usmDESPrivProtocol` (default if *authKey* is given)
        * :py:class:`~pysnmp.hlapi.usm3DESEDEPrivProtocol`
        * :py:class:`~pysnmp.hlapi.usmAesCfb128Protocol`
        * :py:class:`~pysnmp.hlapi.usmAesCfb192Protocol`
        * :py:class:`~pysnmp.hlapi.usmAesCfb256Protocol`


    authKeyType: :py:class:`int`
        Type of `authKey` material. See :RFC:`3414#section-2.6` for
        technical explanation.

        Supported key types are:

        * :py:class:`~pysnmp.hlapi.usmKeyTypePassphrase` (default)
        * :py:class:`~pysnmp.hlapi.usmKeyTypeMaster`
        * :py:class:`~pysnmp.hlapi.usmKeyTypeLocalized`

    privKeyType: :py:class:`int`
        Type of `privKey` material. See :RFC:`3414#section-2.6` for
        technical explanation.

        Supported key types are:

        * :py:class:`~pysnmp.hlapi.usmKeyTypePassphrase` (default)
        * :py:class:`~pysnmp.hlapi.usmKeyTypeMaster`
        * :py:class:`~pysnmp.hlapi.usmKeyTypeLocalized`

    Notes
    -----
    If :py:class:`~pysnmp.hlapi.usmKeyTypeLocalized` is used when
    running a non-authoritative SNMP engine, USM key localization
    mechanism is not invoked. As a consequence, local SNMP engine
    configuration won't get automatically populated with remote SNMP
    engine's *securityEngineId*.

    Therefore peer SNMP engine's *securityEngineId* must be added
    to local configuration and associated with its localized keys.

    Alternatively, the magic *securityEngineId* value of five zeros
    (*0x0000000000*) can be used to refer to the localized keys that
    should be used with any unknown remote SNMP engine. This feature
    is specific to pysnmp.

    Examples
    --------
    >>> from pysnmp.hlapi import UsmUserData
    >>> UsmUserData('testuser', authKey='authenticationkey')
    UsmUserData(userName='testuser', authKey=<AUTHKEY>, privKey=<PRIVKEY>, authProtocol=(1,3,6,1,6,3,10,1,1,2), privProtocol=(1,3,6,1,6,3,10,1,2,1))
    >>> UsmUserData('testuser', authKey='authenticationkey', privKey='encryptionkey')
    UsmUserData(userName='testuser', authKey=<AUTHKEY>, privKey=<PRIVKEY>, authProtocol=(1,3,6,1,6,3,10,1,1,2), privProtocol=(1,3,6,1,6,3,10,1,2,2))
    >>>

    Nr      c
           
      C   s   || _ |d u r|| _n|| _|d ur)|| _|d u rtj| _n|| _| jdkr)d| _|d urJ|| _| jtjkr;t	
dd| _|d u rGtj| _n|| _|| _|| _|	| _d S )NZauthPrivZ
authNoPrivzPrivacy implies authenticity)userNamer    authKeyr   r   authProtocolr5   privKeyr   r   ZPySnmpErrorr   privProtocolsecurityEngineIdauthKeyTypeprivKeyType
r"   r7   r8   r:   r9   r;   r<   r    r=   r>   r#   r#   r$   r%   `  s,   




zUsmUserData.__init__c                 C   r&   r'   r(   r,   r#   r#   r$   r-     r.   zUsmUserData.__hash__c              	   C   s8   d| j j| j| j| j| jd u rdp| j| j| j| jf S )Nz%s(userName=%r, authKey=<AUTHKEY>, privKey=<PRIVKEY>, authProtocol=%r, privProtocol=%r, securityEngineId=%r, securityName=%r, authKeyType=%r, privKeyType=%r)z	<DEFAULT>)	r*   r+   r7   r9   r;   r<   r    r=   r>   r,   r#   r#   r$   r/     s   zUsmUserData.__repr__c
           
      C   s   |  |d u r	| jp
||d u r| jp||d u r| jp||d u r!| jp"||d u r)| jp*||d u r1| jp2||d u r9| jp:||d u rA| jpBt	|	d u rI| j
pJt		S r0   )r*   r7   r8   r:   r9   r;   r<   r    r=   usmKeyTypePassphraser>   r?   r#   r#   r$   r1     s   zUsmUserData.clone)	NNNNNNNNN)r+   r2   r3   r4   r8   r:   r   r   r9   r   r;   r5   r   r   r   r   r@   r%   r-   r/   r1   r#   r#   r#   r$   r      s0    }
$r   N)Zpysnmp.entityr   Zpysnmpr   Zpyasn1.compat.octetsr   __all__objectr   r   r   r   r   r   r   r   r   r   r   r   r	   r
   r   r   r@   ZusmKeyTypeMasterZusmKeyTypeLocalizedr   r#   r#   r#   r$   <module>   sV    