Skip to content

Commit

Permalink
Add tar gz
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 24, 2024
1 parent c2fecaa commit dbad0b0
Show file tree
Hide file tree
Showing 29 changed files with 2,311 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/uv-extract/src/stream.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fs;
use std::path::Path;
use std::pin::Pin;

Expand Down Expand Up @@ -65,6 +66,7 @@ pub async fn unzip<R: tokio::io::AsyncRead + Unpin>(
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;


// To avoid lots of small reads to `reader` when parsing the central directory, wrap it in
// a buffer.
let mut buf = futures::io::BufReader::new(reader);
Expand Down
Binary file added original.tar.gz
Binary file not shown.
Binary file added pgpdump-1.5.tar.gz
Binary file not shown.
Binary file added pgpdump-1.5.zip
Binary file not shown.
31 changes: 31 additions & 0 deletions pgpdump-1.5/COPYRIGHT
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Copyright (C) 2011-2014, Dan McGee.
All rights reserved.

Derived from 'pgpdump'. http://www.mew.org/~kazu/proj/pgpdump/
Copyright (C) 1998, Kazuhiko Yamamoto.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the author nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18 changes: 18 additions & 0 deletions pgpdump-1.5/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Metadata-Version: 1.1
Name: pgpdump
Version: 1.5
Summary: PGP packet parser library
Home-page: https://github.com/toofishes/python-pgpdump
Author: Dan McGee
Author-email: UNKNOWN
License: BSD
Description: UNKNOWN
Keywords: pgp gpg rfc2440 rfc4880 crypto cryptography
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: Software Development :: Libraries :: Python Modules
1 change: 1 addition & 0 deletions pgpdump-1.5/README
17 changes: 17 additions & 0 deletions pgpdump-1.5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# python-pgpdump: a Python library for parsing PGP packets

This is based on the C version published at:
http://www.mew.org/~kazu/proj/pgpdump/

The intent here is not on completeness, as we don't currently decode every
packet type, but on being able to do what people actually have to 95% of the
time. Currently supported things include:

* Signature packets
* Public key packets
* Secret key packets
* Trust, user ID, and user attribute packets
* ASCII-armor decoding and CRC check

A single codebase with dependencies on only the standard python library is
compatible across Python 2.6, 2.7, and 3.2+, as well as with PyPy 1.8+.
36 changes: 36 additions & 0 deletions pgpdump-1.5/pgpdump/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (C) 2011-2014, Dan McGee.
# All rights reserved.
#
# Derived from 'pgpdump'. http://www.mew.org/~kazu/proj/pgpdump/
# Copyright (C) 1998, Kazuhiko Yamamoto.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the author nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__version__ = "1.5"
__author__ = "Dan McGee"

from .data import AsciiData, BinaryData
30 changes: 30 additions & 0 deletions pgpdump-1.5/pgpdump/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys

from . import AsciiData, BinaryData


def parsefile(name):
with open(name, 'rb') as infile:
if name.endswith('.asc') or name.endswith('.txt'):
data = AsciiData(infile.read())
else:
data = BinaryData(infile.read())

for packet in data.packets():
yield packet


def main():
counter = length = 0
for filename in sys.argv[1:]:
for packet in parsefile(filename):
counter += 1
length += packet.length

print('%d packets, length %d' % (counter, length))


if __name__ == '__main__':
#import cProfile
#cProfile.run('main()', 'pgpdump.profile')
main()
103 changes: 103 additions & 0 deletions pgpdump-1.5/pgpdump/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from base64 import b64decode

from .packet import construct_packet
from .utils import PgpdumpException, crc24


class BinaryData(object):
'''The base object used for extracting PGP data packets. This expects fully
binary data as input; such as that read from a .sig or .gpg file.'''
binary_tag_flag = 0x80

def __init__(self, data):
if not data:
raise PgpdumpException("no data to parse")
if len(data) <= 1:
raise PgpdumpException("data too short")

data = bytearray(data)

# 7th bit of the first byte must be a 1
if not bool(data[0] & self.binary_tag_flag):
raise PgpdumpException("incorrect binary data")
self.data = data
self.length = len(data)

def packets(self):
'''A generator function returning PGP data packets.'''
offset = 0
while offset < self.length:
total_length, packet = construct_packet(self.data, offset)
offset += total_length
yield packet

def __repr__(self):
return "<%s: length %d>" % (
self.__class__.__name__, self.length)


class AsciiData(BinaryData):
'''A wrapper class that supports ASCII-armored input. It searches for the
first PGP magic header and extracts the data contained within.'''
def __init__(self, data):
self.original_data = data
data = self.strip_magic(data)
data, known_crc = self.split_data_crc(data)
data = bytearray(b64decode(data))
if known_crc:
# verify it if we could find it
actual_crc = crc24(data)
if known_crc != actual_crc:
raise PgpdumpException(
"CRC failure: known 0x%x, actual 0x%x" % (
known_crc, actual_crc))
super(AsciiData, self).__init__(data)

@staticmethod
def strip_magic(data):
'''Strip away the '-----BEGIN PGP SIGNATURE-----' and related cruft so
we can safely base64 decode the remainder.'''
idx = 0
magic = b'-----BEGIN PGP '
ignore = b'-----BEGIN PGP SIGNED '

# find our magic string, skiping our ignored string
while True:
idx = data.find(magic, idx)
if data[idx:len(ignore)] != ignore:
break
idx += 1

if idx >= 0:
# find the start of the actual data. it always immediately follows
# a blank line, meaning headers are done.
nl_idx = data.find(b'\n\n', idx)
if nl_idx < 0:
nl_idx = data.find(b'\r\n\r\n', idx)
if nl_idx < 0:
raise PgpdumpException(
"found magic, could not find start of data")
# now find the end of the data.
end_idx = data.find(b'-----', nl_idx)
if end_idx:
data = data[nl_idx:end_idx]
else:
data = data[nl_idx:]
return data

@staticmethod
def split_data_crc(data):
'''The Radix-64 format appends any CRC checksum to the end of the data
block, in the form '=alph', where there are always 4 ASCII characters
correspnding to 3 digits (24 bits). Look for this special case.'''
# don't let newlines trip us up
data = data.rstrip()
# this funkyness makes it work without changes in Py2 and Py3
if data[-5] in (b'=', ord(b'=')):
# CRC is returned without the = and converted to a decimal
crc = b64decode(data[-4:])
# same noted funkyness as above, due to bytearray implementation
crc = [ord(c) if isinstance(c, str) else c for c in crc]
crc = (crc[0] << 16) + (crc[1] << 8) + crc[2]
return (data[:-5], crc)
return (data, None)
Loading

0 comments on commit dbad0b0

Please sign in to comment.