Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Pgp-Encrypted Files #110

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/matchers/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,8 @@ func Marc(in []byte) bool {
// Field terminator is present
return bytes.Contains(in, []byte{0x1E})
}

// Pgp matches a pgp-encrypted file
func Pgp(in []byte) bool {
return len(in) >= 4 && in[0] == 0x85 && in[3] == 0x03
}
5 changes: 5 additions & 0 deletions internal/matchers/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,8 @@ func VCard(in []byte) bool {
func ICalendar(in []byte) bool {
return detect(in, iCalSigs)
}

// PgpAscii matches an ascii-armored pgp-encrypted file
func PgpAscii(in []byte) bool {
return bytes.HasPrefix(in, []byte("-----BEGIN PGP MESSAGE-----"))
}
2 changes: 2 additions & 0 deletions mimetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ var files = map[string]string{
"xz.xz": "application/x-xz",
"zip.zip": "application/zip",
"zst.zst": "application/zstd",
"pgp.pgp": "application/pgp-encrypted",
"pgp.2.pgp": "application/pgp-encrypted",
}

func TestDetect(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion supported_mimes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 149 Supported MIME types
## 151 Supported MIME types
This file is automatically generated when running tests. Do not edit manually.

Extension | MIME type | Aliases
Expand Down Expand Up @@ -147,8 +147,10 @@ Extension | MIME type | Aliases
**.vcf** | text/vcard | -
**.ics** | text/calendar | -
**.warc** | application/warc | -
**.pgp** | application/pgp-encrypted | -
**.rpm** | application/x-rpm | -
**.xz** | application/x-xz | -
**.lz** | application/lzip | -
**.torrent** | application/x-bittorrent | -
**.cpio** | application/x-cpio | -
**.pgp** | application/pgp-encrypted | -
12 changes: 12 additions & 0 deletions testdata/pgp.2.pgp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-----BEGIN PGP MESSAGE-----

hQEOA1e+1x6YuUMCEAP6A1tKg+VgyUM2PisHQXiMGRXT1Nn6MfF5t6EDQnkrndqw
DBweVbhW9reWxgjrbmxrHIHGuOVL+0c53Km9ETQvMywJnr6570hL04zjsVOC/Y96
vk0uFREW/PdPL1PnV938T0AAuIB1c9lkIi490KNqPjxmIF9ZI3yUgpmQNCmhttME
AJVJoBAsyu0Zsne3aZW3EIoN4+dEjB8+B44gm9g5vnSK3vYi48jynhQD0CZeX5ka
E29T11fs8IFId6heWWQewNMBGgtKERL+W4b79zgMbhB0oMBZyh07YIK/gKG3fQa1
ixWcbo0xDnZ6Zmto5NCBgV39sYpMzBfcTAkug8jFgLye0mgB5ZyinjoZyz1HSE7I
0DHgs9UiGfdVgWXL4A6BfQ8SN9wm5wKW2hGxNc+XyqxraaNHMl9Yt8BKQtihTqWz
oESZ4Y0ZrS3S5s1MI2zcb/LKjlkVx2F+4PvT6lyQ4f8g6NKRBS653W1ONg==
=6F0C
-----END PGP MESSAGE-----
Binary file added testdata/pgp.pgp
Binary file not shown.
30 changes: 16 additions & 14 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var root = newMIME("application/octet-stream", "", func([]byte) bool { return tr
utf16le, utf16be, gzip, class, swf, crx, ttf, woff, woff2, otf, eot, wasm,
shx, dbf, dcm, rar, djvu, mobi, lit, bpg, sqlite3, dwg, nes, macho, qcp,
icns, heic, heicSeq, heif, heifSeq, mrc, mdb, accdb, zstd, cab, utf8,
rpm, xz, lzip, torrent, cpio,
rpm, xz, lzip, torrent, cpio, pgp,
)

// The list of nodes appended to the root node.
Expand Down Expand Up @@ -52,7 +52,7 @@ var (
utf32be = newMIME("text/plain; charset=utf-32be", ".txt", matchers.Utf32be)
utf16le = newMIME("text/plain; charset=utf-16le", ".txt", matchers.Utf16le)
utf16be = newMIME("text/plain; charset=utf-16be", ".txt", matchers.Utf16be)
utf8 = newMIME("text/plain; charset=utf-8", ".txt", matchers.Utf8, html, svg, xml, php, js, lua, perl, python, json, ndJson, rtf, tcl, csv, tsv, vCard, iCalendar, warc)
utf8 = newMIME("text/plain; charset=utf-8", ".txt", matchers.Utf8, html, svg, xml, php, js, lua, perl, python, json, ndJson, rtf, tcl, csv, tsv, vCard, iCalendar, warc, pgpAscii)
xml = newMIME("text/xml; charset=utf-8", ".xml", matchers.Xml, rss, atom, x3d, kml, xliff, collada, gml, gpx, tcx, amf, threemf)
json = newMIME("application/json", ".json", matchers.Json, geoJson)
csv = newMIME("text/csv", ".csv", matchers.Csv)
Expand Down Expand Up @@ -190,16 +190,18 @@ var (
sqlite3 = newMIME("application/x-sqlite3", ".sqlite", matchers.Sqlite)
dwg = newMIME("image/vnd.dwg", ".dwg", matchers.Dwg).
alias("image/x-dwg", "application/acad", "application/x-acad", "application/autocad_dwg", "application/dwg", "application/x-dwg", "application/x-autocad", "drawing/dwg")
warc = newMIME("application/warc", ".warc", matchers.Warc)
nes = newMIME("application/vnd.nintendo.snes.rom", ".nes", matchers.Nes)
macho = newMIME("application/x-mach-binary", ".macho", matchers.MachO)
qcp = newMIME("audio/qcelp", ".qcp", matchers.Qcp)
mrc = newMIME("application/marc", ".mrc", matchers.Marc)
mdb = newMIME("application/x-msaccess", ".mdb", matchers.MsAccessMdb)
accdb = newMIME("application/x-msaccess", ".accdb", matchers.MsAccessAce)
zstd = newMIME("application/zstd", ".zst", matchers.Zstd)
cab = newMIME("application/vnd.ms-cab-compressed", ".cab", matchers.Cab)
lzip = newMIME("application/lzip", ".lz", matchers.Lzip)
torrent = newMIME("application/x-bittorrent", ".torrent", matchers.Torrent)
cpio = newMIME("application/x-cpio", ".cpio", matchers.Cpio)
warc = newMIME("application/warc", ".warc", matchers.Warc)
nes = newMIME("application/vnd.nintendo.snes.rom", ".nes", matchers.Nes)
macho = newMIME("application/x-mach-binary", ".macho", matchers.MachO)
qcp = newMIME("audio/qcelp", ".qcp", matchers.Qcp)
mrc = newMIME("application/marc", ".mrc", matchers.Marc)
mdb = newMIME("application/x-msaccess", ".mdb", matchers.MsAccessMdb)
accdb = newMIME("application/x-msaccess", ".accdb", matchers.MsAccessAce)
zstd = newMIME("application/zstd", ".zst", matchers.Zstd)
cab = newMIME("application/vnd.ms-cab-compressed", ".cab", matchers.Cab)
lzip = newMIME("application/lzip", ".lz", matchers.Lzip)
torrent = newMIME("application/x-bittorrent", ".torrent", matchers.Torrent)
cpio = newMIME("application/x-cpio", ".cpio", matchers.Cpio)
pgp = newMIME("application/pgp-encrypted", ".pgp", matchers.Pgp)
pgpAscii = newMIME("application/pgp-encrypted", ".pgp", matchers.PgpAscii)
)