FingerprintToKeyID() static private method

Extracts the key ID from a key fingerprint.
static private FingerprintToKeyID ( [ fingerprint ) : long
fingerprint [
return long
Esempio n. 1
0
        private static OpenPgpSignature ParseSignatureLine([NotNull] string line)
        {
            const int signatureTypeIndex = 1, fingerprintIndex = 2, timestampIndex = 4, keyIDIndex = 2, errorCodeIndex = 7;

            string[] signatureParts = line.Split(' ');
            if (signatureParts.Length < signatureTypeIndex + 1)
            {
                return(null);
            }
            switch (signatureParts[signatureTypeIndex])
            {
            case "VALIDSIG":
                if (signatureParts.Length != 12)
                {
                    throw new FormatException("Incorrect number of columns in VALIDSIG line.");
                }
                var fingerprint = OpenPgpUtils.ParseFingerpint(signatureParts[fingerprintIndex]);
                return(new ValidSignature(
                           keyID: OpenPgpUtils.FingerprintToKeyID(fingerprint),
                           fingerprint: fingerprint,
                           timestamp: FileUtils.FromUnixTime(Int64.Parse(signatureParts[timestampIndex]))));

            case "BADSIG":
                if (signatureParts.Length < 3)
                {
                    throw new FormatException("Incorrect number of columns in BADSIG line.");
                }
                return(new BadSignature(OpenPgpUtils.ParseKeyID(signatureParts[keyIDIndex])));

            case "ERRSIG":
                if (signatureParts.Length != 8)
                {
                    throw new FormatException("Incorrect number of columns in ERRSIG line.");
                }
                int errorCode = Int32.Parse(signatureParts[errorCodeIndex]);
                switch (errorCode)
                {
                case 9:
                    return(new MissingKeySignature(OpenPgpUtils.ParseKeyID(signatureParts[keyIDIndex])));

                default:
                    return(new ErrorSignature(OpenPgpUtils.ParseKeyID(signatureParts[keyIDIndex])));
                }

            default:
                return(null);
            }
        }
 public void TestFingerprintToKeyID()
 => OpenPgpUtils.FingerprintToKeyID(OpenPgpUtils.ParseFingerprint("E91FE1CBFCCF315543F6CB13DEED44B49BE24661"))
 .Should().Be(OpenPgpUtils.ParseKeyID("DEED44B49BE24661"));