See https://tools.ietf.org/html/rfc4880#section-5.2 for details.
351529
def _parse_signature(stream):
    """"""
    p = {'type': 'signature'}

    to_hash = io.BytesIO()
    with stream.capture(to_hash):
        p['version'] = stream.readfmt('B')
        p['sig_type'] = stream.readfmt('B')
        p['pubkey_alg'] = stream.readfmt('B')
        p['hash_alg'] = stream.readfmt('B')
        p['hashed_subpackets'] = parse_subpackets(stream)

    # https://tools.ietf.org/html/rfc4880#section-5.2.4
    tail_to_hash = b'\x04\xff' + struct.pack('>L', to_hash.tell())

    p['_to_hash'] = to_hash.getvalue() + tail_to_hash

    p['unhashed_subpackets'] = parse_subpackets(stream)
    embedded = list(_parse_embedded_signatures(p['unhashed_subpackets']))
    if embedded:
        log.debug('embedded sigs: %s', embedded)
        p['embedded'] = embedded

    p['hash_prefix'] = stream.readfmt('2s')
    if p['pubkey_alg'] in ECDSA_ALGO_IDS:
        p['sig'] = (parse_mpi(stream), parse_mpi(stream))
    elif p['pubkey_alg'] in RSA_ALGO_IDS:  # RSA
        p['sig'] = (parse_mpi(stream),)
    elif p['pubkey_alg'] == DSA_ALGO_ID:
        p['sig'] = (parse_mpi(stream), parse_mpi(stream))
    else:
        log.error('unsupported public key algo: %d', p['pubkey_alg'])

    assert not stream.read()
    return p
534568
def _domain_event_block_threshold_cb(conn, domain, dev, path, threshold, excess, opaque):
    '''
    
    '''
    _salt_send_domain_event(opaque, conn, domain, opaque['event'], {
        'dev': dev,
        'path': path,
        'threshold': threshold,
        'excess': excess
    })
987573
def i2m(self, pkt, i):
        """""""  # noqa: E501
        mask, ip = i
        ip = pton_ntop.inet_pton(socket.AF_INET6, ip)
        return struct.pack(">B", mask) + ip[:self.mask2iplen(mask)]
1095448
private static Collection<String> toWsBalancerURIs(Collection<String> uris,
                                                    AcceptOptionsContext acceptOptionsCtx,
                                                    TransportFactory transportFactory) throws Exception {
        List<String> httpURIs = new ArrayList<>(uris.size());
        for (String uri : uris) {
            String schemeFromAcceptURI = uri.substring(0, uri.indexOf(':'));
            Protocol protocol = transportFactory.getProtocol(schemeFromAcceptURI);
            if( WsProtocol.WS.equals(protocol) || WsProtocol.WSS.equals(protocol)) {
                for (String scheme: Arrays.asList("wsn", "wsx")) {
                    boolean secure = protocol.isSecure();
                    String wsBalancerUriScheme = secure ? scheme+"+ssl" : scheme;
                    String httpAuthority = getAuthority(uri);
                    String httpPath = getPath(uri);
                    String httpQuery = getQuery(uri);
                    httpURIs.add(buildURIAsString(wsBalancerUriScheme, httpAuthority, httpPath, httpQuery, null));

                    // ensure that the accept-options is updated with bindings if they exist for ws and/or wss
                    // so that the Gateway binds to the correct host:port as per the service configuration.
                    String internalURI = acceptOptionsCtx.getInternalURI(uri);
                    if ((internalURI != null) && !internalURI.equals(uri)) {
                        String authority = getAuthority(internalURI);
                        acceptOptionsCtx.addBind(wsBalancerUriScheme, authority);
                    }
                }
            }
        }
        return httpURIs;
    }
615900
private int getDatanodeHttpPort(Configuration conf) {
    String address = conf.get("dfs.datanode.http.address", "");
    if (address.equals("")) {
      return -1;
    }
    return Integer.parseInt(address.split(":")[1]);
  }
455809
def routingAreaUpdateRequest(PTmsiSignature_presence=0,
                             GprsTimer_presence=0,
                             DrxParameter_presence=0,
                             TmsiStatus_presence=0):
    """"""
    a = TpPd(pd=0x3)
    b = MessageType(mesType=0x8)  # 00001000
    c = UpdateTypeAndCiphKeySeqNr()
    e = RoutingAreaIdentification()
    f = MsNetworkCapability()
    packet = a / b / c / e / f
    if PTmsiSignature_presence is 1:
        g = PTmsiSignature(ieiPTS=0x19)
        packet = packet / g
    if GprsTimer_presence is 1:
        h = GprsTimer(ieiGT=0x17)
        packet = packet / h
    if DrxParameter_presence is 1:
        i = DrxParameter(ieiDP=0x27)
        packet = packet / i
    if TmsiStatus_presence is 1:
        j = TmsiStatus(ieiTS=0x9)
        packet = packet / j
    return packet
329294
def _domain_event_tunable_cb(conn, domain, params, opaque):
    '''
    
    '''
    _salt_send_domain_event(opaque, conn, domain, opaque['event'], {
        'params': params
    })
309928
public void marshalling(Xdr xdr) {
        super.marshalling(xdr);
        xdr.putString(_name);
        xdr.putUnsignedInt(_type.getValue());
        if ((_type == NfsType.NFS_BLK) || (_type == NfsType.NFS_CHR)) {
            _attributes.marshalling(xdr);
            xdr.putUnsignedInt(_rdev[0]);
            xdr.putUnsignedInt(_rdev[1]);
        } else if ((_type == NfsType.NFS_SOCK) || (_type == NfsType.NFS_FIFO)) {
            _attributes.marshalling(xdr);
        }
    }
371888
def indication(self, apdu):
        """"""
        if _debug: ClientSSM._debug("indication %r", apdu)

        # make sure we're getting confirmed requests
        if (apdu.apduType != ConfirmedRequestPDU.pduType):
            raise RuntimeError("invalid APDU (1)")

        # save the request and set the segmentation context
        self.set_segmentation_context(apdu)

        # if the max apdu length of the server isn't known, assume that it
        # is the same size as our own and will be the segment size
        if (not self.device_info) or (self.device_info.maxApduLengthAccepted is None):
            self.segmentSize = self.maxApduLengthAccepted

        # if the max npdu length of the server isn't known, assume that it
        # is the same as the max apdu length accepted
        elif self.device_info.maxNpduLength is None:
            self.segmentSize = self.device_info.maxApduLengthAccepted

        # the segment size is the minimum of the size of the largest packet
        # that can be delivered to the server and the largest it can accept
        else:
            self.segmentSize = min(self.device_info.maxNpduLength, self.device_info.maxApduLengthAccepted)
        if _debug: ClientSSM._debug("    - segment size: %r", self.segmentSize)

        # save the invoke ID
        self.invokeID = apdu.apduInvokeID
        if _debug: ClientSSM._debug("    - invoke ID: %r", self.invokeID)

        # compute the segment count
        if not apdu.pduData:
            # always at least one segment
            self.segmentCount = 1
        else:
            # split into chunks, maybe need one more
            self.segmentCount, more = divmod(len(apdu.pduData), self.segmentSize)
            if more:
                self.segmentCount += 1
        if _debug: ClientSSM._debug("    - segment count: %r", self.segmentCount)

        # make sure we support segmented transmit if we need to
        if self.segmentCount > 1:
            if self.segmentationSupported not in ('segmentedTransmit', 'segmentedBoth'):
                if _debug: ClientSSM._debug("    - local device can't send segmented requests")
                abort = self.abort(AbortReason.segmentationNotSupported)
                self.response(abort)
                return

            if not self.device_info:
                if _debug: ClientSSM._debug("    - no server info for segmentation support")

            elif self.device_info.segmentationSupported not in ('segmentedReceive', 'segmentedBoth'):
                if _debug: ClientSSM._debug("    - server can't receive segmented requests")
                abort = self.abort(AbortReason.segmentationNotSupported)
                self.response(abort)
                return

            # make sure we dont exceed the number of segments in our request
            # that the server said it was willing to accept
            if not self.device_info:
                if _debug: ClientSSM._debug("    - no server info for maximum number of segments")

            elif not self.device_info.maxSegmentsAccepted:
                if _debug: ClientSSM._debug("    - server doesn't say maximum number of segments")

            elif self.segmentCount > self.device_info.maxSegmentsAccepted:
                if _debug: ClientSSM._debug("    - server can't receive enough segments")
                abort = self.abort(AbortReason.apduTooLong)
                self.response(abort)
                return

        # send out the first segment (or the whole thing)
        if self.segmentCount == 1:
            # unsegmented
            self.sentAllSegments = True
            self.retryCount = 0
            self.set_state(AWAIT_CONFIRMATION, self.apduTimeout)
        else:
            # segmented
            self.sentAllSegments = False
            self.retryCount = 0
            self.segmentRetryCount = 0
            self.initialSequenceNumber = 0
            self.actualWindowSize = None    # segment ack will set value
            self.set_state(SEGMENTED_REQUEST, self.segmentTimeout)

        # deliver to the device
        self.request(self.get_segment(0))
315920
function protocol(value) {
  var val = value.slice(-6).toLowerCase()
  return val === mailto || val.slice(-5) === https || val.slice(-4) === http
}
1068861
private void encodeThis() throws IOException {
        if (certPolicies == null || certPolicies.isEmpty()) {
            this.extensionValue = null;
        } else {
            DerOutputStream os = new DerOutputStream();
            DerOutputStream tmp = new DerOutputStream();

            for (PolicyInformation info : certPolicies) {
                info.encode(tmp);
            }

            os.write(DerValue.tag_Sequence, tmp);
            this.extensionValue = os.toByteArray();
        }
    }
1303094
def setMetadata(self, remote, address, key, value):
        """"""
        try:
            return self.proxies["%s-%s" % (self._interface_id, remote)].setMetadata(address, key, value)
        except Exception as err:
            LOG.debug("ServerThread.setMetadata: Exception: %s" % str(err))
795907
def _set_transmaps(self):
        """"""
        if self._std == 'ascii':
            self._lower_chars = string.ascii_lowercase
            self._upper_chars = string.ascii_uppercase

        elif self._std == 'rfc1459':
            self._lower_chars = (string.ascii_lowercase +
                                 ''.join(chr(i) for i in range(123, 127)))
            self._upper_chars = (string.ascii_uppercase +
                                 ''.join(chr(i) for i in range(91, 95)))

        elif self._std == 'rfc1459-strict':
            self._lower_chars = (string.ascii_lowercase +
                                 ''.join(chr(i) for i in range(123, 126)))
            self._upper_chars = (string.ascii_uppercase +
                                 ''.join(chr(i) for i in range(91, 94)))
1119584
function() {
    this.cantWebsocket = vAPI.cantWebsocket;
    this.reBadDomainOptChars = /[*+?^${}()[\]\\]/;
    this.reHostnameRule1 = /^[0-9a-z][0-9a-z.-]*[0-9a-z]$/i;
    this.reHostnameRule2 = /^[0-9a-z][0-9a-z.-]*[0-9a-z]\^?$/i;
    this.reCleanupHostnameRule2 = /\^$/g;
    this.reCanTrimCarets1 = /^[^*]*$/;
    this.reCanTrimCarets2 = /^\^?[^^]+[^^][^^]+\^?$/;
    this.reHasUppercase = /[A-Z]/;
    this.reIsolateHostname = /^(\*?\.)?([^\x00-\x24\x26-\x2C\x2F\x3A-\x5E\x60\x7B-\x7F]+)(.*)/;
    this.reHasUnicode = /[^\x00-\x7F]/;
    this.reWebsocketAny = /^ws[s*]?(?::\/?\/?)?\*?$/;
    this.reBadCSP = /(?:^|;)\s*report-(?:to|uri)\b/;
    this.domainOpt = '';
    this.noTokenHash = µb.urlTokenizer.noTokenHash;
    this.unsupportedTypeBit = this.bitFromType('unsupported');
    // All network request types to bitmap
    //   bring origin to 0 (from 4 -- see typeNameToTypeValue)
    //   left-shift 1 by the above-calculated value
    //   subtract 1 to set all type bits
    this.allNetRequestTypeBits = (1 << (otherTypeBitValue >>> 4)) - 1;
    this.reset();
}
819510
def connectMsToNet(Facility_presence=0, ConnectedSubaddress_presence=0,
                   UserUser_presence=0, SsVersionIndicator_presence=0):
    """"""
    a = TpPd(pd=0x3)
    b = MessageType(mesType=0x7)  # 00000111
    packet = a / b
    if Facility_presence is 1:
        c = FacilityHdr(ieiF=0x1C, eightBitF=0x0)
        packet = packet / c
    if ConnectedSubaddress_presence is 1:
        d = ConnectedSubaddressHdr(ieiCS=0x4D, eightBitCS=0x0)
        packet = packet / d
    if UserUser_presence is 1:
        e = UserUserHdr(ieiUU=0x7F, eightBitUU=0x0)
        packet = packet / e
    if SsVersionIndicator_presence is 1:
        f = SsVersionIndicatorHdr(ieiSVI=0x7F, eightBitSVI=0x0)
        packet = packet / f
    return packet
617023
def _send_packet_safe(self, cr, packet):
        
        # packet = bytearray(packet)
        packet[0] &= 0xF3
        packet[0] |= self._curr_up << 3 | self._curr_down << 2
        resp = cr.send_packet(packet)
        if resp and resp.ack and len(resp.data) and \
           (resp.data[0] & 0x04) == (self._curr_down << 2):
            self._curr_down = 1 - self._curr_down
        if resp and resp.ack:
            self._curr_up = 1 - self._curr_up

        return resp
638283
def send_pgrp(cls, sock, pgrp):
    """"""
    assert(isinstance(pgrp, IntegerForPid) and pgrp < 0)
    encoded_int = cls.encode_int(pgrp)
    cls.write_chunk(sock, ChunkType.PGRP, encoded_int)