Return a serial number in hex using os.urandom() and a Unix timestamp
    in microseconds.

    ca_name
        name of the CA
    CN
        common name in the request
191786
def _new_serial(ca_name):
    '''
    
    '''
    hashnum = int(
        binascii.hexlify(
            b'_'.join((
                salt.utils.stringutils.to_bytes(_microtime()),
                os.urandom(5) if six.PY3 else os.urandom(5).encode('hex')
            ))
        ),
        16
    )
    log.debug('Hashnum: %s', hashnum)

    # record the hash somewhere
    cachedir = __opts__['cachedir']
    log.debug('cachedir: %s', cachedir)
    serial_file = '{0}/{1}.serial'.format(cachedir, ca_name)
    if not os.path.exists(cachedir):
        os.makedirs(cachedir)
    if not os.path.exists(serial_file):
        mode = 'w'
    else:
        mode = 'a+'
    with salt.utils.files.fopen(serial_file, mode) as ofile:
        ofile.write(str(hashnum))  # future lint: disable=blacklisted-function

    return hashnum
888196
def hex(self):
        
        return "#{:02x}{:02x}{:02x}".format(self._r, self._g, self._b).upper()
560794
def int2str(num, radix=10, alphabet=BASE85):
    """"""
    return NumConv(radix, alphabet).int2str(num)
51906
def getName(self, length=512):
        
        name = ctypes.create_string_buffer(length)
        self._ioctl(_HIDIOCGRAWNAME(length), name, True)
        return name.value.decode('UTF-8')
1001793
def read_name(self):
        """"""
        result = ''
        off = self.offset
        next = -1
        first = off

        while 1:
            len = ord(self.data[off])
            off += 1
            if len == 0:
                break
            t = len & 0xC0
            if t == 0x00:
                result = ''.join((result, self.read_utf(off, len) + '.'))
                off += len
            elif t == 0xC0:
                if next < 0:
                    next = off + 1
                off = ((len & 0x3F) << 8) | ord(self.data[off])
                if off >= first:
                    raise Exception(
                            "Bad domain name (circular) at " + str(off))
                first = off
            else:
                raise Exception("Bad domain name at " + str(off))

        if next >= 0:
            self.offset = next
        else:
            self.offset = off

        return result
413008
def _VarUInt64ByteSizeNoTag(uint64):
  
  if uint64 <= 0x7f: return 1
  if uint64 <= 0x3fff: return 2
  if uint64 <= 0x1fffff: return 3
  if uint64 <= 0xfffffff: return 4
  if uint64 <= 0x7ffffffff: return 5
  if uint64 <= 0x3ffffffffff: return 6
  if uint64 <= 0x1ffffffffffff: return 7
  if uint64 <= 0xffffffffffffff: return 8
  if uint64 <= 0x7fffffffffffffff: return 9
  if uint64 > UINT64_MAX:
    raise message.EncodeError('Value out of range: %d' % uint64)
  return 10
310198
def generate_nonce_timestamp():
    
    global count
    rng = botan.rng().get(30)
    uuid4 = uuid.uuid4().bytes  # 16 byte
    tmpnonce = (bytes(str(count).encode('utf-8'))) + uuid4 + rng
    nonce = tmpnonce[:41]  # 41 byte (328 bit)
    count += 1
    return nonce
599861
def name2unicode(name):
    """"""
    if name in glyphname2unicode:
        return glyphname2unicode[name]
    m = STRIP_NAME.search(name)
    if not m:
        raise KeyError(name)
    return unichr(int(m.group(0)))
217819
def get_serial_number(device):
        
        a0000 = 604661760
        if device.SerialNumber >= a0000:
            return ics.base36enc(device.SerialNumber)
        return str(device.SerialNumber)
1080115
def format_hex(i, num_bytes=4, prefix='0x'):
    
    prefix = str(prefix or '')
    i = int(i or 0)
    return prefix + '{0:0{1}x}'.format(i, num_bytes)
20175
def crc_srec(hexstr):
    

    crc = sum(bytearray(binascii.unhexlify(hexstr)))
    crc &= 0xff
    crc ^= 0xff

    return crc
1111645
def get_mac(self):
        '''  '''
        ifreq = struct.pack('16sH14s', self.name, AF_UNIX, b'\x00'*14)
        res = fcntl.ioctl(sockfd, SIOCGIFHWADDR, ifreq)
        address = struct.unpack('16sH14s', res)[2]
        mac = struct.unpack('6B8x', address)

        return ":".join(['%02X' % i for i in mac])
657917
function uuid() {
  return crypto.randomBytes(4).toString('hex') + '-' +
    crypto.randomBytes(2).toString('hex') + '-' +
    crypto.randomBytes(2).toString('hex').replace(/^./, '1') + '-' +
    crypto.randomBytes(2).toString('hex') + '-' +
    crypto.randomBytes(6).toString('hex')
}
505013
def mac_address(self) -> str:
        
        mac_hex = [
            0x00, 0x16, 0x3e,
            self.random.randint(0x00, 0x7f),
            self.random.randint(0x00, 0xff),
            self.random.randint(0x00, 0xff),
        ]
        mac = map(lambda x: '%02x' % x, mac_hex)
        return ':'.join(mac)
1324660
def byte_str(nBytes, unit='bytes', precision=2):
    
    #return (nBytes * ureg.byte).to(unit.upper())
    if unit.lower().startswith('b'):
        nUnit = nBytes
    elif unit.lower().startswith('k'):
        nUnit =  nBytes / (2.0 ** 10)
    elif unit.lower().startswith('m'):
        nUnit =  nBytes / (2.0 ** 20)
    elif unit.lower().startswith('g'):
        nUnit = nBytes / (2.0 ** 30)
    elif unit.lower().startswith('t'):
        nUnit = nBytes / (2.0 ** 40)
    else:
        raise NotImplementedError('unknown nBytes=%r unit=%r' % (nBytes, unit))
    return repr2(nUnit, precision=precision) + ' ' + unit
481916
def repr_size(n_bytes):
    
    if n_bytes < 1024:
        return '{0} Bytes'.format(n_bytes)
    i = -1
    while n_bytes > 1023:
        n_bytes /= 1024.0
        i += 1
    return '{0} {1}iB'.format(round(n_bytes, 1), si_prefixes[i])
544027
def _decode_name(raw_name, platform_id, encoding_id):
        
        if platform_id == 1:
            # reject non-Roman Mac font names
            if encoding_id != 0:
                return None
            return raw_name.decode('mac-roman')
        elif platform_id in (0, 3):
            return raw_name.decode('utf-16-be')
        else:
            return None