:param buffer: a binary buffer (e.g. serialized blob)
    :return: the first 8 characters of base64 ASCII rendition SHA-1
331317
def short_hash(*buffers):
    
    hashed = hashlib.sha1()
    for buffer in buffers:
        hashed.update(buffer)
    return to_ascii(hashed.digest())[:8]
1233456
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
      if bson_int32?
        buffer.put_int32(self)
      elsif bson_int64?
        buffer.put_int64(self)
      else
        out_of_range!
      end
    end
1046665
def decode_modified_utf8(s: bytes) -> str:
    
    s = bytearray(s)
    buff = []
    buffer_append = buff.append
    ix = 0
    while ix < len(s):
        x = s[ix]
        ix += 1

        if x >> 7 == 0:
            # Just an ASCII character, nothing else to do.
            pass
        elif x >> 6 == 6:
            y = s[ix]
            ix += 1
            x = ((x & 0x1F) << 6) + (y & 0x3F)
        elif x >> 4 == 14:
            y, z = s[ix:ix+2]
            ix += 2
            x = ((x & 0xF) << 12) + ((y & 0x3F) << 6) + (z & 0x3F)
        elif x == 0xED:
            v, w, x, y, z = s[ix:ix+6]
            ix += 5
            x = 0x10000 + (
                ((v & 0x0F) << 16) +
                ((w & 0x3F) << 10) +
                ((y & 0x0F) << 6) +
                (z & 0x3F)
            )
        elif x == 0xC0 and s[ix] == 0x80:
            ix += 1
            x = 0
        buffer_append(x)
    return u''.join(chr(b) for b in buff)
651805
def get_body_hash(params):
    
    norm_params = get_normalized_params(params)

    return binascii.b2a_base64(hashlib.sha1(norm_params).digest())[:-1]
81460
function arrayBufferToBinaryString(buffer) {
  var binary = '';
  var bytes = new Uint8Array(buffer);
  var length = bytes.byteLength;
  for (var i = 0; i < length; i++) {
    binary += String.fromCharCode(bytes[i]);
  }
  return binary;
}
789138
def decode_body(buffer, header=nil)
      return [nil, buffer] if buffer.size < Frame.header_size

      header ||= decode_header buffer[0, Frame.header_size + Frame.mac_size]
      body_size = Frame.decode_body_size header

      if @frame_cipher
        body = @frame_cipher.decrypt_body(buffer[(Frame.header_size+Frame.mac_size)..-1], body_size)
        raise MultiplexerError, 'body length mismatch' unless body.size == body_size

        bytes_read = Frame.header_size + Frame.mac_size + Utils.ceil16(body.size) + Frame.mac_size
      else
        header = buffer[0, Frame.header_size]
        body_offset = Frame.header_size + Frame.mac_size
        body = buffer[body_offset, body_size]
        raise MultiplexerError, 'body length mismatch' unless body.size == body_size

        bytes_read = Utils.ceil16(body_offset + body_size + Frame.mac_size)
      end
      raise MultiplexerError, "bytes not padded" unless bytes_read % Frame.padding == 0

      # normal, chunked-n: RLP::List.new(protocol_type[, sequence_id])
      # chunked-0: RLP::List.new(protocol_type, sequence_id, total_packet_size)
      header_data = nil
      begin
        header_data = RLP.decode(header[3..-1], sedes: Frame.header_sedes, strict: false)
      rescue RLP::Error::RLPException => e
        logger.error(e)
        raise MultiplexerError, 'invalid rlp data'
      end

      if header_data.size == 3
        chunked_0 = true
        total_payload_size = header_data[2]
        raise MultiplexerError, "invalid total payload size" unless total_payload_size < 2**32
      else
        chunked_0 = false
        total_payload_size = nil
      end

      protocol_id = header_data[0]
      raise MultiplexerError, "invalid protocol id" unless protocol_id < TT16

      if header_data.size > 1
        sequence_id = header_data[1]
        raise MultiplexerError, "invalid sequence id" unless sequence_id < TT16
      else
        sequence_id = nil
      end

      raise MultiplexerError, "unknown protocol id #{protocol_id}" unless @chunked_buffers.has_key?(protocol_id)

      chunkbuf = @chunked_buffers[protocol_id]
      if chunkbuf.has_key?(sequence_id)
        packet = chunkbuf[sequence_id]

        raise MultiplexerError, "received chunked_0 frame for existing buffer #{sequence_id} of protocol #{protocol_id}" if chunked_0
        raise MultiplexerError, "too much data for chunked buffer #{sequence_id} of protocol #{protocol_id}" if body.size > (packet.total_payload_size - packet.payload.size)

        packet.payload += body
        if packet.total_payload_size == packet.payload.size
          packet.total_payload_size = nil
          chunkbuf.delete sequence_id
          return packet
        end
      else
        # body of normal, chunked_0: rlp(packet-type) [|| rlp(packet-data)] || padding
        item, item_end = RLP.consume_item(body, 0)
        cmd_id = RLP::Sedes.big_endian_int.deserialize item

        if chunked_0
          payload = body[item_end..-1]
          total_payload_size -= item_end
        else
          payload = body[item_end..-1]
        end

        packet = Packet.new protocol_id, cmd_id, payload
        if chunked_0
          raise MultiplexerError, "total payload size smaller than initial chunk" if total_payload_size < payload.size

          # shouldn't have been chunked, whatever
          return packet if total_payload_size == payload.size

          raise MultiplexerError, 'chunked_0 must have sequence id' if sequence_id.nil?

          packet.total_payload_size = total_payload_size
          chunkbuf[sequence_id] = packet

          return nil
        else
          return packet # normal (non-chunked)
        end
      end
    end
1114679
def decode(self, buf):
        
        index = 0
        if self.length > len(buf):
            raise exc.ParseError("Insufficient data for reading header.") 
        for (name, nbytes, typecode) in self.format:
            string = buf[index:index + nbytes]
            index += nbytes
            value = struct.unpack('<' + typecode, string)[0]
            setattr(self, name, value)
        if const.DB_SIGNATURE1 != self.signature1 or \
                const.DB_SIGNATURE2 != self.signature2:
            msg = 'Bad signatures: {0} {0}'.format(hex(self.signature1),
                                                   hex(self.signature2))
            raise exc.InvalidDatabase(msg)
75153
function _btoa(str) {
  let buffer;

  if (str instanceof Buffer) {
    buffer = str;
  } else {
    buffer = Buffer.from(str.toString(), "binary");
  }

  return buffer.toString("base64");
}
947871
function b64encode(str) {
    const buf = Buffer.isBuffer(str) ? str : Buffer.from(str);
    return b64escape(buf.toString('base64'));
}
857192
function base64ArrayBuffer(bytes) {
    var base64    = ''
    var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'

    var byteLength    = bytes.byteLength
    var byteRemainder = byteLength % 3
    var mainLength    = byteLength - byteRemainder
   
    var a, b, c, d
    var chunk
   
    // Main loop deals with bytes in chunks of 3
    for (var i = 0; i < mainLength; i = i + 3) {
      // Combine the three bytes into a single integer
      chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]
   
      // Use bitmasks to extract 6-bit segments from the triplet
      a = (chunk & 16515072) >> 18 // 16515072 = (2^6 - 1) << 18
      b = (chunk & 258048)   >> 12 // 258048   = (2^6 - 1) << 12
      c = (chunk & 4032)     >>  6 // 4032     = (2^6 - 1) << 6
      d = chunk & 63               // 63       = 2^6 - 1
   
      // Convert the raw binary segments to the appropriate ASCII encoding
      base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]
    }
   
    // Deal with the remaining bytes and padding
    if (byteRemainder == 1) {
      chunk = bytes[mainLength]
   
      a = (chunk & 252) >> 2 // 252 = (2^6 - 1) << 2
   
      // Set the 4 least significant bits to zero
      b = (chunk & 3)   << 4 // 3   = 2^2 - 1
   
      base64 += encodings[a] + encodings[b] + '=='
    } else if (byteRemainder == 2) {
      chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]
   
      a = (chunk & 64512) >> 10 // 64512 = (2^6 - 1) << 10
      b = (chunk & 1008)  >>  4 // 1008  = (2^6 - 1) << 4
   
      // Set the 2 least significant bits to zero
      c = (chunk & 15)    <<  2 // 15    = 2^4 - 1
   
      base64 += encodings[a] + encodings[b] + encodings[c] + '='
    }
    
    return base64
  }
911642
public static long fromByteBuffer(ByteBuffer buf) {
      if (buf.remaining() < 1) {
         // XXX make all callers check for -1
         return -1;
      }
      long first = 0x00000000000000FFL & ((long) buf.get());
      long value;
      if (first < 253) {
         // Regard this byte as a 8 bit value.
         value = 0x00000000000000FFL & ((long) first);
      } else if (first == 253) {
         // Regard the following two bytes as a 16 bit value
         if (buf.remaining() < 2) {
            return -1;
         }
         buf.order(ByteOrder.LITTLE_ENDIAN);
         value = 0x0000000000FFFFL & ((long) buf.getShort());
      } else if (first == 254) {
         // Regard the following four bytes as a 32 bit value
         if (buf.remaining() < 4) {
            return -1;
         }
         buf.order(ByteOrder.LITTLE_ENDIAN);
         value = 0x00000000FFFFFFFF & ((long) buf.getInt());
      } else {
         // Regard the following four bytes as a 64 bit value
         if (buf.remaining() < 8) {
            return -1;
         }
         buf.order(ByteOrder.LITTLE_ENDIAN);
         value = buf.getLong();
      }
      return value;
   }
921686
def encrypt_ascii(self, data, key=None, v=None, extra_bytes=0,
                      digest="hex"):
        
        digests = {"hex": binascii.b2a_hex,
                   "base64": binascii.b2a_base64,
                   "hqx": binascii.b2a_hqx}
        digestor = digests.get(digest)
        if not digestor:
            TripleSecError(u"Digestor not supported.")

        binary_result = self.encrypt(data, key, v, extra_bytes)
        result = digestor(binary_result)
        return result
74366
def encode_bytes(self):
        
        with io.StringIO() as buf:
            for char in self.data:
                if not isinstance(char, int):
                    buf.write('{{0:0{0}b}}'.format(8).format(ord(char)))
                else:
                    buf.write('{{0:0{0}b}}'.format(8).format(char))
            return buf.getvalue()
720760
def sha1_hexdigest(self):
        # type: () -> str
        
        if self._sha1_hexdigest is None:
            self._sha1_hexdigest = hashlib.sha1(self._pem_bytes).hexdigest()

        return self._sha1_hexdigest
909157
function encode(buf) {
	if (buf.length != 8) {
		throw new TypeError("Buffer must be length 8");
	}

	var num = new UInt64(buf.readUInt32BE(4), buf.readUInt32BE(0));
	var str = "";
	do {
		num.div(SIXTY_TWO);
		str = CHARS[num.remainder] + str;
	} while (num.greaterThan(ZERO));

	return str;
}
568732
synchronized public int encodeIntoByteBuffer(final ByteBuffer buffer) {
        final long maxValue = getMaxValue();
        final int relevantLength = countsArrayIndex(maxValue) + 1;
        if (buffer.capacity() < getNeededByteBufferCapacity(relevantLength)) {
            throw new ArrayIndexOutOfBoundsException("buffer does not have capacity for " +
                    getNeededByteBufferCapacity(relevantLength) + " bytes");
        }
        int initialPosition = buffer.position();
        buffer.putInt(getEncodingCookie());
        buffer.putInt(0); // Placeholder for payload length in bytes.
        buffer.putInt(getNormalizingIndexOffset());
        buffer.putInt(numberOfSignificantValueDigits);
        buffer.putLong(lowestDiscernibleValue);
        buffer.putLong(highestTrackableValue);
        buffer.putDouble(getIntegerToDoubleValueConversionRatio());

        int payloadStartPosition = buffer.position();
        fillBufferFromCountsArray(buffer);
        buffer.putInt(initialPosition + 4, buffer.position() - payloadStartPosition); // Record the payload length


        return buffer.position() - initialPosition;
    }
1007492
def base64_b64decode(instr):
    '''
    
    '''
    decoded = base64.b64decode(salt.utils.stringutils.to_bytes(instr))
    try:
        return salt.utils.stringutils.to_unicode(
            decoded,
            encoding='utf8' if salt.utils.platform.is_windows() else None
        )
    except UnicodeDecodeError:
        return decoded