# Path: oppy/cell/exceptions.py
# class BadLinkSpecifier(Exception):
#     pass
# 
# class BadPayloadData(Exception):
#     pass
# 
# Path: oppy/util/tools.py
# def decodeMicrodescriptorIdentifier(microdescriptor):
#     ident = microdescriptor.identifier
#     short = 4-len(ident)%4
#     if short:
#         ident += '='*short
#     return base64.b64decode(ident).rstrip('=')


import ipaddress
import struct
import oppy.cell.definitions as DEF
from oppy.cell.exceptions import BadLinkSpecifier, BadPayloadData
from oppy.util.tools import decodeMicrodescriptorIdentifier
            return self.__dict__ == other.__dict__
        return False

CERT_TYPE_LEN = 1
CERT_LEN_LEN = 2
SUPPORTED_CERT_TYPES = (1, 2, 3,)


class CertsCellPayloadItem(object):
    
    __slots__ = ('cert_type', 'cert_len', 'cert')

    def __init__(self, cert_type, cert_len, cert):
        self.cert_type = cert_type
        self.cert_len = cert_len
        self.cert = cert

    def getBytes(self):
        ret = struct.pack('!B', self.cert_type)
        ret += struct.pack('!H', self.cert_len)
        ret += self.cert
        return ret

    @staticmethod
    def parse(data, offset):
        cert_type = struct.unpack('!B',
                                  data[offset: offset + CERT_TYPE_LEN])[0]
        offset += CERT_TYPE_LEN
        if cert_type not in SUPPORTED_CERT_TYPES:
            msg = "Got cert type {}, but oppy only supports cert types {}."

# Path: oppy/cell/exceptions.py
# class BadLinkSpecifier(Exception):
#     pass
# 
# class BadPayloadData(Exception):
#     pass
# 
# Path: oppy/util/tools.py
# def decodeMicrodescriptorIdentifier(microdescriptor):
#     ident = microdescriptor.identifier
#     short = 4-len(ident)%4
#     if short:
#         ident += '='*short
#     return base64.b64decode(ident).rstrip('=')


# Path: oppy/cell/util.py
import ipaddress
import struct
import oppy.cell.definitions as DEF
from oppy.cell.exceptions import BadLinkSpecifier, BadPayloadData
from oppy.util.tools import decodeMicrodescriptorIdentifier

            return self.__dict__ == other.__dict__
        return False

CERT_TYPE_LEN = 1
CERT_LEN_LEN = 2
SUPPORTED_CERT_TYPES = (1, 2, 3,)


class CertsCellPayloadItem(object):
    
    __slots__ = ('cert_type', 'cert_len', 'cert')

    def __init__(self, cert_type, cert_len, cert):
        self.cert_type = cert_type
        self.cert_len = cert_len
        self.cert = cert

    def getBytes(self):
        ret = struct.pack('!B', self.cert_type)
        ret += struct.pack('!H', self.cert_len)
        ret += self.cert
        return ret

    @staticmethod
    def parse(data, offset):
        cert_type = struct.unpack('!B',
                                  data[offset: offset + CERT_TYPE_LEN])[0]
        offset += CERT_TYPE_LEN
        if cert_type not in SUPPORTED_CERT_TYPES:
            msg = "Got cert type {}, but oppy only supports cert types {}."

            raise BadPayloadData(msg.format(cert_type, SUPPORTED_CERT_TYPES))