Convert PEM formatted data to raw buffer.
@param {Buffer|String} pem
@returns {Buffer}
971343
function decode(pem) {
  if (Buffer.isBuffer(pem)) {
    pem = pem.toString('ascii')
  }

  const lines = pem.trim().split('\n')

  if (lines.length < 3) {
    throw new Error('Invalid PEM data.')
  }

  const match = header.exec(lines[0])

  if (match === null) {
    throw new Error('Invalid label.')
  }

  const label = match[1]
  let i = 1

  for (; i < lines.length; ++i) {
    if (lines[i].startsWith(after)) {
      break
    }
  }

  const footer = new RegExp(`^${after} ${label}${endline}\r?\n?$`)

  if (footer.exec(lines[i]) === null) {
    throw new Error('Invalid end of file.')
  }

  const body = lines.slice(1, i).join('\n').replace(/\r?\n/g, '')
  return Buffer.from(body, 'base64')
}
615532
function(elem) {
			var convert = function(value) {
				return {thin: 1, medium: 3, thick: 5}[value] || value;
			};
			return [parseFloat(convert(elem.css('border-left-width'))),
				parseFloat(convert(elem.css('border-top-width')))];
		}
1191541
def process_pem_rsakey(self, data, name, idx):
        
        from cryptography.hazmat.primitives.serialization import load_der_public_key
        from cryptography.hazmat.primitives.serialization import load_der_private_key
        try:
            if startswith(data, '-----BEGIN RSA PUBLIC KEY') or startswith(data, '-----BEGIN PUBLIC KEY'):
                rsa = load_der_public_key(pem_to_der(data), self.get_backend())
                public_numbers = rsa.public_numbers()
            elif startswith(data, '-----BEGIN RSA PRIVATE KEY') or startswith(data, '-----BEGIN PRIVATE KEY'):
                rsa = load_der_private_key(pem_to_der(data), None, self.get_backend())
                public_numbers = rsa.private_numbers().public_numbers
            else:
                return None
            self.num_rsa_keys += 1
            self.num_rsa += 1

            js = collections.OrderedDict()
            js['type'] = 'pem-rsa-key'
            js['fname'] = name
            js['idx'] = idx
            js['pem'] = data
            js['e'] = '0x%x' % public_numbers.e
            js['n'] = '0x%x' % public_numbers.n

            if self.has_fingerprint(public_numbers.n):
                logger.warning('Fingerprint found in PEM RSA key %s ' % name)
                self.mark_and_add_effort(public_numbers.n, js)

                if self.do_print:
                    print(json.dumps(js))

            return TestResult(js)

        except Exception as e:
            logger.debug('Pubkey loading error: %s : %s [%s] : %s' % (name, idx, data[:20], e))
            self.trace_logger.log(e)
146702
private static byte[] getDecodedPEMObject(BufferedReader reader) throws IOException {
        String line;
        StringBuffer buf = new StringBuffer();
        while ((line = reader.readLine()) != null) {
            if (line.indexOf("--END") != -1) { // found end
                return Base64.decode(buf.toString().getBytes());
            } else {
                buf.append(line);
            }
        }
        throw new EOFException("Missing PEM end footer");
    }
313124
private function pem2der($pem_data) {
        $begin = "CERTIFICATE-----";
        $end   = "-----END";
        $pem_data = substr($pem_data, strpos($pem_data, $begin) + strlen($begin));
        $pem_data = substr($pem_data, 0, strpos($pem_data, $end));

        return  base64_decode($pem_data);
    }
1132129
function normalizePEMContent(root, file) {
  if (Array.isArray(file)) return file.map(function map(item) {
    return normalizePEMContent(root, item)
  });

  //
  // Assumption that this is a Buffer, a PEM file, or something broken
  //
  if (typeof(file) !== 'string' || pemFormat.test(file)) {
    return file;
  }

  return fs.readFileSync(path.resolve(root, file));
}
1287764
def _read_pem_file(cls, filename, from_package=False):
        '''
        '''
        _logger.debug('Reading PEM {0}.'.format(filename))

        if from_package:
            return wpull.util.filter_pem(wpull.util.get_package_data(filename))

        with open(filename, 'rb') as in_file:
            return wpull.util.filter_pem(in_file.read())
546438
function convert (buffer, from, to) {
	//ensure formats are full
	if (!isNormalized(from)) from = normalize(from)
	if (!isNormalized(to)) to = normalize(to)

	//convert buffer/alike to arrayBuffer
	var data
	if (buffer instanceof ArrayBuffer) {
		data = buffer
	}
	else if (ArrayBuffer.isView(buffer)) {
		if (buffer.byteOffset != null) data = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
		else data = buffer.buffer;
	}
	else {
		data = (new Uint8Array(buffer.length != null ? buffer : [buffer])).buffer
	}

	//ignore needless conversion
	if (equal(from ,to)) {
		return data
	}

	//create containers for conversion
	var fromArray = new (arrayClass(from))(data)

	//toArray is automatically filled with mapped values
	//but in some cases mapped badly, e. g. float → int(round + rotate)
	var toArray = new (arrayClass(to))(fromArray)

	//if range differ, we should apply more thoughtful mapping
	if (from.max !== to.max) {
		fromArray.forEach(function (value, idx) {
			//ignore not changed range
			//bring to 0..1
			var normalValue = (value - from.min) / (from.max - from.min)

			//bring to new format ranges
			value = normalValue * (to.max - to.min) + to.min

			//clamp (buffers does not like values outside of bounds)
			toArray[idx] = Math.max(to.min, Math.min(to.max, value))
		})
	}

	//reinterleave, if required
	if (from.interleaved != to.interleaved) {
		var channels = from.channels
		var len = Math.floor(fromArray.length / channels)

		//deinterleave
		if (from.interleaved && !to.interleaved) {
			toArray = toArray.map(function (value, idx, data) {
				var targetOffset = idx % len
				var targetChannel = ~~(idx / len)

				return data[targetOffset * channels + targetChannel]
			})
		}
		//interleave
		else if (!from.interleaved && to.interleaved) {
			toArray = toArray.map(function (value, idx, data) {
				var targetOffset = ~~(idx / channels)
				var targetChannel = idx % channels

				return data[targetChannel * len + targetOffset]
			})
		}
	}

	//ensure endianness
	if (!to.float && from.byteOrder !== to.byteOrder) {
		var le = to.byteOrder === 'LE'
		var view = new DataView(toArray.buffer)
		var step = to.bitDepth / 8
		var methodName = 'set' + getDataViewSuffix(to)
		for (var i = 0, l = toArray.length; i < l; i++) {
			view[methodName](i*step, toArray[i], le)
		}
	}

	return toArray.buffer
}
177499
function stringToArrayBuffer(string) {
            var
                buffer = new ArrayBuffer(string.length),
                int8Array = new Uint8Array(buffer);
            
            for (var i = 0; i < string.length; i++) {
                int8Array[i] = string.charCodeAt(i);
            }
            
            return buffer;
        }
743408
public function decodePEM($pem_data)
    {
        $pem_data = $this->pemDataClean($pem_data);
        $decoded  = bin2hex(base64_decode($pem_data));

        $this->pemDataLenCheck($decoded);

        $ecpemstruct = array(
                             'oct_sec_val'  => substr($decoded, 14, 64),
                             'obj_id_val'   => substr($decoded, 86, 10),
                             'bit_str_val'  => substr($decoded, 106),
                            );

        $this->pemOidCheck($ecpemstruct['obj_id_val']);

        $private_key = $ecpemstruct['oct_sec_val'];
        $public_key  = '04' . $ecpemstruct['bit_str_val'];

        $this->pemKeyLenCheck(array($private_key, $public_key));

        return array(
                     'private_key' => $private_key,
                     'public_key'  => $public_key
                    );
    }
450338
function ws_receive(raw)
{
	let data = unpack(raw); // string to byte array
	let fin = (data[0] & 128) == 128;
	let opcode = data[0] & 15;
	let isMasked = (data[1] & 128) == 128;
    let dataLength = data[1] & 127;
    let start = 2;
	let length = data.length;
	let output = "";
	
    if (dataLength == 126)
        start = 4;
    else if (dataLength == 127)
        start = 10;
        
    if (isMasked) {
		let i = start + 4;
		let masks = data.slice(start, i);
		let index = 0;
	
		while (i < length) {
			output += String.fromCharCode(data[i++] ^ masks[index++ % 4]);
		}
    } else {
		let i = start;
		while (i < length) {
			output += String.fromCharCode(data[i++]);
		}
    }

    //console.log("decode message: " + output);
    return output;
}
67167
function decodeBuffer(buf, options, cb) {
  if (typeof options === 'function') {
    cb = options;
    options = {};
  }

  try {
    buf = bufferUtils.toUint8Array(buf);

    if (_hasWorker.hasWorker) {
      const wr = require('webworkify')(_decodeWorker2.default);

      wr.onmessage = ({ data: msg }) => {
        const err = msg.err ? new Error(msg.err) : undefined;
        cb(err, msg.result);
      };

      const msg = {
        buf: buf,
        options: options
      };

      if (options.transferable) {
        wr.postMessage(msg, [buf]);
      } else {
        wr.postMessage(msg);
      }
    } else {
      (0, _decode2.default)(buf, options, cb);
    }
  } catch (err) {
    cb(err);
  }
}
1163258
private static function sanitizePEM(&$pem)
    {
        preg_match_all('#(-.*-)#', $pem, $matches, PREG_PATTERN_ORDER);
        $ciphertext = preg_replace('#-.*-|\r|\n| #', '', $pem);

        $pem = $matches[0][0].PHP_EOL;
        $pem .= chunk_split($ciphertext, 64, PHP_EOL);
        $pem .= $matches[0][1].PHP_EOL;
    }
770159
async function _convertBlobs (rawArchive) {
  let resources = rawArchive.resources
  let paths = Object.keys(resources)
  for (var i = 0; i < paths.length; i++) {
    let record = resources[paths[i]]
    if (record.encoding === 'blob') {
      record.data = await _blobToArrayBuffer(record.data)
    }
  }
}
874253
function __serializeString(data) {
	let dataBuffer = UTF8Encode(data);
	let length = dataBuffer.byteLength;
	let lengthData = new Uint32Array([length]);
	return [lengthData.buffer, dataBuffer];
}
938404
function toBuffer(b) {
	// TODO: Use nodert-streams to more efficiently convert the buffer?
	let len = b.length;
	const DataReader = Windows.Storage.Streams.DataReader;
	let r = DataReader.fromBuffer(b);
	let a = new Uint8Array(len);
	for (let i = 0; i < len; i++) {
		a[i] = r.readByte();
	}
	return Buffer.from(a.buffer);
}
893697
function bufferToString (buf) {
  const a = bufferToTuples(buf)
  const b = tuplesToStringTuples(a)
  return stringTuplesToString(b)
}