<commit_before>#
# Copyright (c) 2005-2007 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program is distributed in the hope that it will be useful, but
# without any warranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

import os
import sys
import getpass
import tempfile
import subprocess
from time import time

from conary import callbacks
from conary.lib.util import log
from conary.lib import graph

from Crypto.PublicKey import DSA
from openpgpfile import BadPassPhrase
from openpgpfile import PGP_Signature
from openpgpfile import getKeyTrust
from openpgpfile import KeyNotFound
from openpgpfile import num_getRelPrime
from openpgpfile import seekKeyById
from openpgpfile import SEEK_SET, SEEK_END

#-----#
#OpenPGPKey structure:
#-----#

class OpenPGPKey(object):
    __slots__ = ['fingerprint', 'cryptoKey', 'revoked', 'timestamp',
                 'trustLevel', 'signatures']
    def __init__(self, key, cryptoKey, trustLevel=255):
        """
        instantiates a OpenPGPKey object

        @param key: A PGP key
        @type fingerprint: instance of openpgpfile.PGP_Key
        @param cyptoKey: DSA or RSA key object
        @type cryptoKey: instance
        @param trustLevel: the trust level of this key, as stored locally
        @type trustLevel: int
        """

        self.fingerprint = key.getKeyId()
        self.cryptoKey = cryptoKey
        self.revoked, self.timestamp = key.getEndOfLife()
        self.trustLevel = trustLevel
        self.signatures = []
        self._initSignatures(key)

    def _initSignatures(self, key):
        # Iterate over this packet's signatures
        sigs = {}
        keyId = key.getKeyId()
        for sig in key.iterCertifications():
            # Ignore self signatures
            sigKeyId = sig.getSignerKeyId()
            if sigKeyId == keyId:
                continue
            # XXX We should deal with conflict here
            if sigKeyId in sigs:
                continue
            trustLevel, trustAmount, trustRegex = sig.getTrust()
            sigs[sigKeyId] = OpenPGPKeySignature(
                    sigId = sig.getSignatureHash(),
                    signer = sigKeyId,
                    signature = sig.parseMPIs(),
                    pubKeyAlg = sig.pubKeyAlg,
                    hashAlg = sig.hashAlg,
                    creation = sig.getCreation(),
                    expiration = sig.getExpiration(),
                    trustLevel = trustLevel,
                    trustAmount = trustAmount,
                    trustRegex = trustRegex)
        self.signatures = sorted(sigs.values(), key = lambda x: x.signer)

    def getTrustLevel(self):
        return self.trustLevel
<commit_msg>Key ID is not the same as key fingerprint (CNY-1988)<commit_after>#
# Copyright (c) 2005-2007 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program is distributed in the hope that it will be useful, but
# without any warranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

import os
import sys
import getpass
import tempfile
import subprocess
from time import time

from conary import callbacks
from conary.lib.util import log
from conary.lib import graph

from Crypto.PublicKey import DSA
from openpgpfile import BadPassPhrase
from openpgpfile import PGP_Signature
from openpgpfile import getKeyTrust
from openpgpfile import KeyNotFound
from openpgpfile import num_getRelPrime
from openpgpfile import seekKeyById
from openpgpfile import SEEK_SET, SEEK_END

#-----#
#OpenPGPKey structure:
#-----#

class OpenPGPKey(object):
    __slots__ = ['fingerprint', 'cryptoKey', 'revoked', 'timestamp',
                 'trustLevel', 'signatures']
    def __init__(self, key, cryptoKey, trustLevel=255):
        """
        instantiates a OpenPGPKey object

        @param key: A PGP key
        @type fingerprint: instance of openpgpfile.PGP_Key
        @param cyptoKey: DSA or RSA key object
        @type cryptoKey: instance
        @param trustLevel: the trust level of this key, as stored locally
        @type trustLevel: int
        """

        self.fingerprint = key.getKeyId()
        self.cryptoKey = cryptoKey
        self.revoked, self.timestamp = key.getEndOfLife()
        self.trustLevel = trustLevel
        self.signatures = []
        self._initSignatures(key)

    def _initSignatures(self, key):
        # Iterate over this packet's signatures
        sigs = {}
        keyId = key.getKeyId()
        for sig in key.iterCertifications():
            # Ignore self signatures
            sigKeyId = sig.getSignerKeyId()
            if sigKeyId == keyId[-16:]:
                continue
            # XXX We should deal with conflict here
            if sigKeyId in sigs:
                continue
            trustLevel, trustAmount, trustRegex = sig.getTrust()
            sigs[sigKeyId] = OpenPGPKeySignature(
                    sigId = sig.getSignatureHash(),
                    signer = sigKeyId,
                    signature = sig.parseMPIs(),
                    pubKeyAlg = sig.pubKeyAlg,
                    hashAlg = sig.hashAlg,
                    creation = sig.getCreation(),
                    expiration = sig.getExpiration(),
                    trustLevel = trustLevel,
                    trustAmount = trustAmount,
                    trustRegex = trustRegex)
        self.signatures = sorted(sigs.values(), key = lambda x: x.signer)
        print "FFF", self.fingerprint, [x.getSignerKeyId() for x in self.signatures]

    def getTrustLevel(self):
        return self.trustLevel

{'fraction_non_alphanumeric': 0.07364713416586616, 'fraction_numerical': 0.005763688760806916, 'mean_word_length': 2.378583017847485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '481133', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1668, 'n_words': 583}