Esempio n. 1
0
 def test_simple_skipping(self):
     for header in ([], [
             "-----BEGIN PGP SIGNED MESSAGE-----\n", "Hash: Sha1\n", "\n"
     ]):
         d = [
             "asdf\n", "fdsa\n", "-----BEGIN PGP SIGNATURE-----\n",
             "this isn't a valid sig...\n", "-----END PGP SIGNATURE-----\n",
             "foon\n"
         ]
         d2 = header + d
         parsed = list(gpg.skip_signatures(d2))
         required = [d[0], d[1], d[-1]]
         assert parsed == required, f"{parsed!r} != {required!r} for header {header!r}"
Esempio n. 2
0
 def test_signed_signed(self):
     d = [
         "-----BEGIN PGP SIGNED MESSAGE-----\n", "Hash: SHA1\n", "\n",
         "- -----BEGIN PGP SIGNED MESSAGE-----\n", "Hash: SHA1\n", "\n",
         "blah\n", "- -----BEGIN PGP SIGNATURE-----\n",
         "Version: GnuPG v1.4.3 (GNU/Linux)\n", "\n",
         "iD8DBQFEViv+aGfFFLhbXWkRAo+lAJ93s57QA2lW5BE1FdmEc3uzijpJrwCfcE6j",
         "3Nzn/8wExwZ5eUacC/HoSo8=", "=oBur",
         "- -----END PGP SIGNATURE-----\n", "foon\n",
         "-----BEGIN PGP SIGNATURE-----\n", " not valid...\n",
         "-----END PGP SIGNATURE-----\n", "asdf\n"
     ]
     assert list(gpg.skip_signatures(d)) == ["blah\n", "foon\n", "asdf\n"]
Esempio n. 3
0
 def test_simple_skipping(self):
     for header in ([],
         ["-----BEGIN PGP SIGNED MESSAGE-----\n", "Hash: Sha1\n", "\n"]):
         d = ["asdf\n",
             "fdsa\n",
             "-----BEGIN PGP SIGNATURE-----\n",
             "this isn't a valid sig...\n",
             "-----END PGP SIGNATURE-----\n",
             "foon\n"]
         d2 = header + d
         parsed = list(gpg.skip_signatures(d2))
         required = [d[0], d[1], d[-1]]
         self.assertEqual(parsed, required, msg="%r != %r for header %r" %
             (parsed, required, header))
Esempio n. 4
0
 def test_simple_skipping(self):
     for header in (
             [],
             ["-----BEGIN PGP SIGNED MESSAGE-----\n", "Hash: Sha1\n", "\n"]):
         d = [
             "asdf\n",
             "fdsa\n",
             "-----BEGIN PGP SIGNATURE-----\n",
             "this isn't a valid sig...\n",
             "-----END PGP SIGNATURE-----\n",
             "foon\n"]
         d2 = header + d
         parsed = list(gpg.skip_signatures(d2))
         required = [d[0], d[1], d[-1]]
         assert parsed == required, f"{parsed!r} != {required!r} for header {header!r}"
Esempio n. 5
0
 def test_simple_skipping(self):
     for header in ([], [
             "-----BEGIN PGP SIGNED MESSAGE-----\n", "Hash: Sha1\n", "\n"
     ]):
         d = [
             "asdf\n", "fdsa\n", "-----BEGIN PGP SIGNATURE-----\n",
             "this isn't a valid sig...\n", "-----END PGP SIGNATURE-----\n",
             "foon\n"
         ]
         d2 = header + d
         parsed = list(gpg.skip_signatures(d2))
         required = [d[0], d[1], d[-1]]
         self.assertEqual(parsed,
                          required,
                          msg="%r != %r for header %r" %
                          (parsed, required, header))
Esempio n. 6
0
def parse_manifest(source, ignore_gpg=True):
    types = {"DIST":{}, "AUX":{}, "EBUILD":{}, "MISC":{}}
    # manifest v2 format: (see glep 44 for exact rules)
    # TYPE filename size (CHF sum)+
    # example 'type' entry, all one line
    #MISC metadata.xml 219 RMD160 613195ece366b33606e71ff1753be048f2507841 SHA1 d162fb909241ef50b95a3539bdfcde95429bdf81 SHA256 cbd3a20e5c89a48a842f7132fe705bf39959f02c1025052efce8aad8a8baa8dc
    # manifest v1 format is
    # CHF sum filename size
    # note that we do _not_ support manifest1
    chf_types = set(["size"])
    f = None
    try:
        if isinstance(source, basestring):
            i = f = open(source, "r", 32768)
        else:
            i = f = source.text_fileobj()
        if ignore_gpg:
            i = gpg.skip_signatures(f)
        for data in i:
            line = data.split()
            if not line:
                continue
            d = types.get(line[0])
            if d is None:
                raise errors.ParseChksumError(source,
                    "unknown manifest type: %s: %r" % (line[0], line))
            if len(line) % 2 != 1:
                raise errors.ParseChksumError(source,
                    "manifest 2 entry doesn't have right "
                    "number of tokens, %i: %r" %
                    (len(line), line))
            chf_types.update(line[3::2])
            # this is a trick to do pairwise collapsing;
            # [size, 1] becomes [(size, 1)]
            i = iter(line[3:])
            d[line[1]] = [("size", long(line[2]))] + \
                list(convert_chksums(izip(i, i)))
    finally:
        if f is not None and f.close:
            f.close()

    # finally convert it to slotted dict for memory savings.
    slotted_kls = make_SlottedDict_kls(x.lower() for x in chf_types)
    for t, d in types.iteritems():
        types[t] = mappings.ImmutableDict((k, slotted_kls(v)) for k, v in d.iteritems())
    # ordering annoyingly matters. bad api.
    return [types[x] for x in ("DIST", "AUX", "EBUILD", "MISC")]
Esempio n. 7
0
def parse_manifest(source, ignore_gpg=True):
    types = {"DIST": {}, "AUX": {}, "EBUILD": {}, "MISC": {}}
    # manifest v2 format: (see glep 44 for exact rules)
    # TYPE filename size (CHF sum)+
    # example 'type' entry, all one line
    # MISC metadata.xml 219 RMD160 613195ece366b33606e71ff1753be048f2507841 SHA1 d162fb909241ef50b95a3539bdfcde95429bdf81 SHA256 cbd3a20e5c89a48a842f7132fe705bf39959f02c1025052efce8aad8a8baa8dc
    # manifest v1 format is
    # CHF sum filename size
    # note that we do _not_ support manifest1
    chf_types = set(["size"])
    f = None
    try:
        if isinstance(source, basestring):
            i = f = open(source, "r", 32768)
        else:
            i = f = source.text_fileobj()
        if ignore_gpg:
            i = gpg.skip_signatures(f)
        for data in i:
            line = data.split()
            if not line:
                continue
            d = types.get(line[0])
            if d is None:
                raise errors.ParseChksumError(
                    source, "unknown manifest type: %s: %r" % (line[0], line))
            if len(line) % 2 != 1:
                raise errors.ParseChksumError(
                    source, "manifest 2 entry doesn't have right "
                    "number of tokens, %i: %r" % (len(line), line))
            chf_types.update(line[3::2])
            # this is a trick to do pairwise collapsing;
            # [size, 1] becomes [(size, 1)]
            i = iter(line[3:])
            d[line[1]] = [("size", long(line[2]))] + list(
                convert_chksums(izip(i, i)))
    finally:
        if f is not None and f.close:
            f.close()

    # finally convert it to slotted dict for memory savings.
    slotted_kls = make_SlottedDict_kls(x.lower() for x in chf_types)
    for t, d in types.iteritems():
        types[t] = mappings.ImmutableDict(
            (k, slotted_kls(v)) for k, v in d.iteritems())
    # ordering annoyingly matters. bad api.
    return [types[x] for x in ("DIST", "AUX", "EBUILD", "MISC")]
Esempio n. 8
0
 def test_signed_signed(self):
     d = ["-----BEGIN PGP SIGNED MESSAGE-----\n",
         "Hash: SHA1\n",
         "\n",
         "- -----BEGIN PGP SIGNED MESSAGE-----\n",
         "Hash: SHA1\n",
         "\n",
         "blah\n",
         "- -----BEGIN PGP SIGNATURE-----\n",
         "Version: GnuPG v1.4.3 (GNU/Linux)\n",
         "\n",
         "iD8DBQFEViv+aGfFFLhbXWkRAo+lAJ93s57QA2lW5BE1FdmEc3uzijpJrwCfcE6j",
         "3Nzn/8wExwZ5eUacC/HoSo8=",
         "=oBur",
         "- -----END PGP SIGNATURE-----\n",
         "foon\n",
         "-----BEGIN PGP SIGNATURE-----\n",
         " not valid...\n",
         "-----END PGP SIGNATURE-----\n",
         "asdf\n"]
     self.assertEqual(list(gpg.skip_signatures(d)),
         ["blah\n", "foon\n", "asdf\n"])