Go to the latest version of this document.

# ``twisted`.`names`.`_rfc1982`.`SerialNumber``

class documentation

`class SerialNumber(FancyStrMixin): (source)`

Constructor: `SerialNumber(number, serialBits)`

View In Hierarchy

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 Also
https://tools.ietf.org/html/rfc1982
https://tools.ietf.org/html/rfc4034

Class Method | `fromRFC4034DateString` | Create an `SerialNumber` instance from a date string in format 'YYYYMMDDHHMMSS' described in RFC4034 3.2.
Method | `__add__` | Allow addition with another `SerialNumber` instance.
Method | `__eq__` | Allow rich equality comparison with another `SerialNumber` instance.
Method | `__ge__` | Allow greater than or equal comparison with another `SerialNumber` instance.
Method | `__gt__` | Allow greater than comparison with another `SerialNumber` instance.
Method | `__hash__` | Allow `SerialNumber` instances to be hashed for use as `dict` keys.
Method | `__init__` | Construct an `SerialNumber` instance.
Method | `__int__` | No summary
Method | `__le__` | Allow less than or equal comparison with another `SerialNumber` instance.
Method | `__lt__` | Allow less than comparison with another `SerialNumber` instance.
Method | `__str__` | Return a string representation of this `SerialNumber` instance.
Method | `toRFC4034DateString` | Calculate a date by treating the current `SerialNumber` value as a UNIX timestamp and return a date string in the format described in RFC4034 3.2.
Class Variable | `showAttributes` | Undocumented
Method | `_convertOther` | Check that a foreign object is suitable for use in the comparison or arithmetic magic methods of this `SerialNumber` instance. Raise `TypeError` if not.
Instance Variable | `_halfRing` | Half `_modulo`. If another `SerialNumber` value is larger than this, it would lead to a wrapped value which is larger than the first and comparisons are therefore ambiguous.
Instance Variable | `_maxAdd` | Half `_modulo` plus 1. If another `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.
Instance Variable | `_modulo` | The value at which wrapping will occur.
Instance Variable | `_number` | See `number` of `__init__`.
Instance Variable | `_serialBits` | See `serialBits` of `__init__`.

@classmethod
def fromRFC4034DateString(cls, utcDateString): (source)

Create an `SerialNumber` instance from a date string in format 'YYYYMMDDHHMMSS' described in RFC4034 3.2.

The `SerialNumber` instance stores the date as a 32bit UNIX timestamp.

Parameters
utcDateString:`unicode` | A UTC date/time string of format YYMMDDhhmmss which will be converted to seconds since the UNIX epoch.

Returns
An `SerialNumber` instance containing the supplied date as a 32bit UNIX timestamp.

See Also
https://tools.ietf.org/html/rfc4034#section-3.1.5

def __add__(self, other: `object`) -> `SerialNumber`: (source)

Allow addition with another `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.

Raises
`ArithmeticError` | If `other` is more than `_maxAdd` ie more than half the maximum value of this serial number.

See Also
http://tools.ietf.org/html/rfc1982#section-3.1

def __eq__(self, other: `object`) -> `bool`: (source)

Allow rich equality comparison with another `SerialNumber` instance.

def __ge__(self, other: `object`) -> `bool`: (source)

Allow greater than or equal comparison with another `SerialNumber` instance.

def __gt__(self, other: `object`) -> `bool`: (source)

Allow greater than comparison with another `SerialNumber` instance.

def __hash__(self): (source)

Allow `SerialNumber` instances to be hashed for use as `dict` keys.

Returns
`int` | Undocumented

def __init__(self, number: `int`, serialBits: `int` = 32): (source)

Construct an `SerialNumber` instance.

Parameters
number:`int` | An `int` which will be stored as the modulo `number % 2 ^ serialBits`
serialBits:`int` | 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.

def __int__(self): (source)

Returns
`int` | The integer value of this `SerialNumber` instance.

def __le__(self, other: `object`) -> `bool`: (source)

Allow less than or equal comparison with another `SerialNumber` instance.

def __lt__(self, other: `object`) -> `bool`: (source)

Allow less than comparison with another `SerialNumber` instance.

def __str__(self) -> `str`: (source)
overrides `twisted.python.util.FancyStrMixin.__str__`

Return a string representation of this `SerialNumber` instance.

Returns
`nativeString` | Undocumented

def toRFC4034DateString(self): (source)

Calculate a date by treating the current `SerialNumber` value as a UNIX timestamp and return a date string in the format described in RFC4034 3.2.

Returns
The date string.

showAttributes: `tuple` = (source)
overrides `twisted.python.util.FancyStrMixin.showAttributes`

Undocumented

def _convertOther(self, other: `object`) -> `SerialNumber`: (source)

Check that a foreign object is suitable for use in the comparison or arithmetic magic methods of this `SerialNumber` instance. Raise `TypeError` if not.

Parameters
other:`object` | The foreign `object` to be checked.

Returns
`SerialNumber` | `other` after compatibility checks and possible coercion.

Raises
`TypeError` | If `other` is not compatible.

_halfRing: `int` = (source)

Half `_modulo`. If another `SerialNumber` value is larger than this, it would lead to a wrapped value which is larger than the first and comparisons are therefore ambiguous.

_maxAdd = (source)

Half `_modulo` plus 1. If another `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.

_modulo = (source)

The value at which wrapping will occur.

_number: `int` = (source)

See `number` of `__init__`.

_serialBits = (source)

See `serialBits` of `__init__`.