Your IP : 216.73.216.196
B
:��]�# � @ sd d Z ddlmZmZ ddlZddlmZmZ ddlmZ ddl m
Z
dZG dd � d e
e�Z
d gZdS )
a�
Utilities for handling RFC1982 Serial Number Arithmetic.
@see: U{http://tools.ietf.org/html/rfc1982}
@var RFC4034_TIME_FORMAT: RRSIG Time field presentation format. The Signature
Expiration Time and Inception Time field values MUST be represented either
as an unsigned decimal integer indicating seconds since 1 January 1970
00:00:00 UTC, or in the form YYYYMMDDHHmmSS in UTC. See U{RRSIG Presentation
Format<https://tools.ietf.org/html/rfc4034#section-3.2>}
� )�division�absolute_importN)�datetime� timedelta)�nativeString)�
FancyStrMixinz%Y%m%d%H%M%Sc @ s� e Zd ZdZdZd!dd�Zdd� Zdd � Zd
d� Zdd
� Z dd� Z
dd� Zdd� Zdd� Z
dd� Zdd� Zdd� Zedd� �Zdd� Zd S )"�SerialNumbera�
An RFC1982 Serial Number.
This class implements RFC1982 DNS Serial Number Arithmetic.
SNA is used in DNS and specifically in DNSSEC as defined in RFC4034 in the
DNSSEC Signature Expiration and Inception Fields.
@see: U{https://tools.ietf.org/html/rfc1982}
@see: U{https://tools.ietf.org/html/rfc4034}
@ivar _serialBits: See C{serialBits} of L{__init__}.
@ivar _number: See C{number} of L{__init__}.
@ivar _modulo: The value at which wrapping will occur.
@ivar _halfRing: Half C{_modulo}. If another L{SerialNumber} value is larger
than this, it would lead to a wrapped value which is larger than the
first and comparisons are therefore ambiguous.
@ivar _maxAdd: Half C{_modulo} plus 1. If another L{SerialNumber} value is
larger than this, it would lead to a wrapped value which is larger than
the first. Comparisons with the original value would therefore be
ambiguous.
))�_number�numberz%d)�_serialBits�
serialBitsz%d� c C sD || _ d| | _d|d | _d|d d | _t|�| j | _dS )a�
Construct an L{SerialNumber} instance.
@param number: An L{int} which will be stored as the modulo
C{number % 2 ^ serialBits}
@type number: L{int}
@param serialBits: The size of the serial number space. The power of two
which results in one larger than the largest integer corresponding
to a serial number value.
@type serialBits: L{int}
� � N)r �_modulo� _halfRing�_maxAdd�intr )�selfr
r � r �I/opt/alt/python37/lib64/python3.7/site-packages/twisted/names/_rfc1982.py�__init__; s
zSerialNumber.__init__c C s: t |t�std| |f ��| j|jkr6td| |f ��|S )a�
Check that a foreign object is suitable for use in the comparison or
arithmetic magic methods of this L{SerialNumber} instance. Raise
L{TypeError} if not.
@param other: The foreign L{object} to be checked.
@return: C{other} after compatibility checks and possible coercion.
@raises: L{TypeError} if C{other} is not compatible.
z#cannot compare or combine %r and %rzUcannot compare or combine SerialNumber instances with different serialBits. %r and %r)�
isinstancer � TypeErrorr )r �otherr r r �
_convertOtherO s
zSerialNumber._convertOtherc C s t d| jf �S )zs
Return a string representation of this L{SerialNumber} instance.
@rtype: L{nativeString}
z%d)r r )r r r r �__str__e s zSerialNumber.__str__c C s | j S )ze
@return: The integer value of this L{SerialNumber} instance.
@rtype: L{int}
)r )r r r r �__int__n s zSerialNumber.__int__c C s | � |�}|j| jkS )z}
Allow rich equality comparison with another L{SerialNumber} instance.
@type other: L{SerialNumber}
)r r )r r r r r �__eq__v s
zSerialNumber.__eq__c C s | � |� S )z}
Allow rich equality comparison with another L{SerialNumber} instance.
@type other: L{SerialNumber}
)r )r r r r r �__ne__� s zSerialNumber.__ne__c C sF | � |�}| j|jk r(|j| j | jk pD| j|jkoD| j|j | jkS )z|
Allow I{less than} comparison with another L{SerialNumber} instance.
@type other: L{SerialNumber}
)r r r )r r r r r �__lt__� s
zSerialNumber.__lt__c C sF | � |�}| j|jk r(|j| j | jkpD| j|jkoD| j|j | jk S )z�
Allow I{greater than} comparison with another L{SerialNumber} instance.
@type other: L{SerialNumber}
@rtype: L{bool}
)r r r )r r r r r �__gt__� s
zSerialNumber.__gt__c C s | � |�}| |kp| |k S )z�
Allow I{less than or equal} comparison with another L{SerialNumber}
instance.
@type other: L{SerialNumber}
@rtype: L{bool}
)r )r r r r r �__le__� s
zSerialNumber.__le__c C s | � |�}| |kp| |kS )z�
Allow I{greater than or equal} comparison with another L{SerialNumber}
instance.
@type other: L{SerialNumber}
@rtype: L{bool}
)r )r r r r r �__ge__� s
zSerialNumber.__ge__c C sJ | � |�}|j| jkr2t| j|j | j | jd�S td|j| jf ��dS )a�
Allow I{addition} with another L{SerialNumber} instance.
Serial numbers may be incremented by the addition of a positive
integer n, where n is taken from the range of integers
[0 .. (2^(SERIAL_BITS - 1) - 1)]. For a sequence number s, the
result of such an addition, s', is defined as
s' = (s + n) modulo (2 ^ SERIAL_BITS)
where the addition and modulus operations here act upon values that are
non-negative values of unbounded size in the usual ways of integer
arithmetic.
Addition of a value outside the range
[0 .. (2^(SERIAL_BITS - 1) - 1)] is undefined.
@see: U{http://tools.ietf.org/html/rfc1982#section-3.1}
@type other: L{SerialNumber}
@rtype: L{SerialNumber}
@raises: L{ArithmeticError} if C{other} is more than C{_maxAdd}
ie more than half the maximum value of this serial number.
)r z"value %r outside the range 0 .. %rN)r r r r r r �ArithmeticError)r r r r r �__add__� s
zSerialNumber.__add__c C s
t | j�S )zo
Allow L{SerialNumber} instances to be hashed for use as L{dict} keys.
@rtype: L{int}
)�hashr )r r r r �__hash__� s zSerialNumber.__hash__c C s&