Parse the V2 signing block and extract all features
552005
def parse_v3_signing_block(self):
        

        self._v3_signing_data = []

        # calling is_signed_v3 should also load the signature, if any
        if not self.is_signed_v3():
            return

        block_bytes = self._v2_blocks[self._APK_SIG_KEY_V3_SIGNATURE]
        block = io.BytesIO(block_bytes)
        view = block.getvalue()

        # V3 signature Block data format:
        #
        # * signer:
        #    * signed data:
        #        * digests:
        #            * signature algorithm ID (uint32)
        #            * digest (length-prefixed) 
        #        * certificates
        #        * minSDK
        #        * maxSDK
        #        * additional attributes
        #    * minSDK
        #    * maxSDK
        #    * signatures
        #    * publickey
        size_sequence = self.read_uint32_le(block)
        if size_sequence + 4 != len(block_bytes):
            raise BrokenAPKError("size of sequence and blocksize does not match")

        while block.tell() < len(block_bytes):
            off_signer = block.tell()
            size_signer = self.read_uint32_le(block)

            # read whole signed data, since we might to parse
            # content within the signed data, and mess up offset
            len_signed_data = self.read_uint32_le(block)
            signed_data_bytes = block.read(len_signed_data)
            signed_data = io.BytesIO(signed_data_bytes)

            # Digests
            len_digests = self.read_uint32_le(signed_data)
            raw_digests = signed_data.read(len_digests)
            digests = self.parse_signatures_or_digests(raw_digests)


            # Certs
            certs = []
            len_certs = self.read_uint32_le(signed_data)
            start_certs = signed_data.tell()
            while signed_data.tell() < start_certs + len_certs:

                len_cert = self.read_uint32_le(signed_data)
                cert = signed_data.read(len_cert)
                certs.append(cert)

            # versions
            signed_data_min_sdk = self.read_uint32_le(signed_data)
            signed_data_max_sdk = self.read_uint32_le(signed_data)

            # Addional attributes
            len_attr = self.read_uint32_le(signed_data)
            attr = signed_data.read(len_attr)

            signed_data_object = APKV3SignedData()
            signed_data_object._bytes = signed_data_bytes
            signed_data_object.digests = digests
            signed_data_object.certificates = certs
            signed_data_object.additional_attributes = attr
            signed_data_object.minSDK = signed_data_min_sdk
            signed_data_object.maxSDK = signed_data_max_sdk

            # versions (should be the same as signed data's versions)
            signer_min_sdk = self.read_uint32_le(block)
            signer_max_sdk = self.read_uint32_le(block)

            # Signatures
            len_sigs = self.read_uint32_le(block)
            raw_sigs = block.read(len_sigs)
            sigs = self.parse_signatures_or_digests(raw_sigs)

            # PublicKey
            len_publickey = self.read_uint32_le(block)
            publickey = block.read(len_publickey)

            signer = APKV3Signer()
            signer._bytes = view[off_signer:off_signer+size_signer]
            signer.signed_data = signed_data_object
            signer.signatures = sigs
            signer.public_key = publickey
            signer.minSDK = signer_min_sdk
            signer.maxSDK = signer_max_sdk

            self._v3_signing_data.append(signer)
1214129
def signature(self, block_size=None):
        ""
        kwargs = {}
        if block_size:
            kwargs['block_size'] = block_size
        return self.api.get('path/sync/signature', self.path, **kwargs)
352624
def extract_actions_info( lines, blocks, file_name )
      info = []
      blocks = [] unless blocks

      blocks.each do |b|
        if lines[ b[:init] ].include? "=begin action"
          n_lines = b[:end] - b[:init] - 1

          begin
            info << YAML.load( lines[ b[:init] + 1, n_lines ].join.gsub(/\ *#/, '') )
          rescue Exception => e
            puts "Error parsing block in #{file_name} file [#{b[:init]} - #{b[:end]}]"
          end
        end
      end

      return info
    end
604865
def get_signatures(self):
        
        signatures = self.request_list('GetSignatures')

        return [zobjects.Signature.from_dict(i) for i in signatures]
529135
function packetlistCloneToSignatures(clone) {
  clone.keyid = type_keyid.fromClone(clone.keyid);
  if (util.isStream(clone.signature)) {
    clone.signature = stream.readToEnd(clone.signature, ([signature]) => new Signature(List.fromStructuredClone(signature)));
    clone.signature.catch(() => {});
  } else {
    clone.signature = new Signature(List.fromStructuredClone(clone.signature));
  }
  clone.verified = stream.readToEnd(clone.verified, ([verified]) => verified);
  clone.verified.catch(() => {});
  if (clone.error) {
    clone.error = new Error(clone.error);
  }
  return clone;
}
353863
def calculate_signatures(self):
        
        if not self.signing_algorithm:
            return []

        algo_id = {'sha1': 1, 'sha384': 2}[self.signing_algorithm]
        hashers = [(algo_id, make_hasher(algo_id))]
        for block in get_signature_data(self.fileobj, self.filesize):
            [h.update(block) for (_, h) in hashers]

        signatures = [(algo_id, sign_hash(self.signing_key, h.finalize(), h.algorithm.name)) for (algo_id, h) in hashers]
        return signatures
1221879
def get_staged_signatures(vcs):
    
    staged_path = _get_staged_history_path(vcs)
    known_signatures = []
    if os.path.exists(staged_path):
        with open(staged_path, 'r') as f:
            known_signatures = f.read().split()
    return known_signatures
734619
def from_signed_raw(cls: Type[IdentityType], signed_raw: str) -> IdentityType:
        
        n = 0
        lines = signed_raw.splitlines(True)

        version = int(Identity.parse_field("Version", lines[n]))
        n += 1

        Identity.parse_field("Type", lines[n])
        n += 1

        currency = Identity.parse_field("Currency", lines[n])
        n += 1

        pubkey = Identity.parse_field("Issuer", lines[n])
        n += 1

        uid = Identity.parse_field("UniqueID", lines[n])
        n += 1

        ts = BlockUID.from_str(Identity.parse_field("Timestamp", lines[n]))
        n += 1

        signature = Identity.parse_field("Signature", lines[n])

        return cls(version, currency, pubkey, uid, ts, signature)
843004
def _deserialize_v2(self, deserialized):
        '''
        '''
        from pymacaroons.macaroon import Macaroon, MACAROON_V2
        from pymacaroons.caveat import Caveat
        caveats = []
        for c in deserialized.get('c', []):
            caveat = Caveat(
                caveat_id=_read_json_binary_field(c, 'i'),
                verification_key_id=_read_json_binary_field(c, 'v'),
                location=_read_json_binary_field(c, 'l'),
                version=MACAROON_V2
            )
            caveats.append(caveat)
        return Macaroon(
            location=_read_json_binary_field(deserialized, 'l'),
            identifier=_read_json_binary_field(deserialized, 'i'),
            caveats=caveats,
            signature=binascii.hexlify(
                _read_json_binary_field(deserialized, 's')),
            version=MACAROON_V2
        )
229680
def parse_version(vstring):
    
    try:
        version = StrictVersion(vstring)
    except ValueError:
        logging.getLogger('ipvs.common.debug').info('Strict parsing failed, falling back to LooseVersion instead')
        version = LooseVersion(vstring)
        version.version = tuple(version.version)

    return version
940834
def parse(cls, backend, ik, spk, spk_signature, otpks):
        

        ik = backend.decodePublicKey(ik)[0]

        spk["key"] = backend.decodePublicKey(spk["key"])[0]

        otpks = list(map(lambda otpk: {
            "key" : backend.decodePublicKey(otpk["key"])[0],
            "id"  : otpk["id"]
        }, otpks))

        return cls(ik, spk, spk_signature, otpks)
1164515
def old_signing_text(self):
        """"""
        result = []
        lower_cmp = lambda x, y: cmp(x[0].lower(), y[0].lower())
        for key, value in sorted(self.params.items(), cmp=lower_cmp):
            result.append("%s%s" % (key, value))
        return "".join(result)
569644
def parse_pkg_info(fn):
    
    res = {}
    for ln in open(fn).read().splitlines():
        if not ln or not ln[:1].strip():
            continue
        key, value = ln.split(": ", 1)
        res[key] = value
    return res
304267
def sign(mv):
    
    md5 = hashlib.md5()
    update_hash(md5, mv)
    return md5.digest()
538619
def parse_dsn(dsn):
    """"""
    parsed_dsn = urlparse(dsn)
    parsed_path = parse_path(parsed_dsn.path)
    return {
        'scheme': parsed_dsn.scheme,
        'sender': parsed_dsn.username,
        'token': parsed_dsn.password,
        'domain': parsed_dsn.hostname,
        'port': parsed_dsn.port or 80,
        'version': parsed_path.get('version'),
        'project': parsed_path.get('project'),
    }
640144
def _caveat_v2_to_dict(c):
    ''' 
    '''
    serialized = {}
    if len(c.caveat_id_bytes) > 0:
        _add_json_binary_field(c.caveat_id_bytes, serialized, 'i')
    if c.verification_key_id:
        _add_json_binary_field(c.verification_key_id, serialized, 'v')
    if c.location:
        serialized['l'] = c.location
    return serialized
1263381
def signature
      # Remove 'sha_sign' key from request params and concatenate all
      # key value pairs
      params = payload.to_h
        .reject { |key, value| key == :sha_sign }
        .reject { |key, value| value == '' || value == false }.sort
        .map { | key, value| "#{key}=#{value}#{passphrase}" }.join

      # Calculate SHA512 and upcase all letters, since Digistore will
      # also return upcased letters in the signature.
      Digest::SHA512.hexdigest(params).upcase
    end