Skip to content

Commit

Permalink
Add support for PGP (#367)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
akime- and sindresorhus authored Jun 2, 2020
1 parent b977dc4 commit 4a851af
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
6 changes: 4 additions & 2 deletions core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ declare namespace core {
| 'skp'
| 'avif'
| 'eps'
| 'lzh';
| 'lzh'
| 'pgp';

type MimeType =
| 'image/jpeg'
Expand Down Expand Up @@ -258,7 +259,8 @@ declare namespace core {
| 'video/MP2P'
| 'application/vnd.sketchup.skp'
| 'image/avif'
| 'application/x-lzh-compressed';
| 'application/x-lzh-compressed'
| 'application/pgp-encrypted';

interface FileTypeResult {
/**
Expand Down
7 changes: 7 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,13 @@ async function _fromTokenizer(tokenizer) {
};
}

if (checkString('-----BEGIN PGP MESSAGE-----')) {
return {
ext: 'pgp',
mime: 'application/pgp-encrypted'
};
}

// Check for MPEG header at different starting offsets
for (let start = 0; start < 2 && start < (buffer.length - 16); start++) {
// Check MPEG 1 or 2 Layer 3 header, or 'layer 0' for ADTS (MPEG sync-word 0xFFE)
Expand Down
14 changes: 14 additions & 0 deletions fixture/fixture.pgp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PGP MESSAGE-----
Version: OpenPGP.js v3.0.9
Comment: https://openpgpjs.org

wcBMA5C5XtMJioU5AQf/VlCbKDYaUD2UaAVVM4jJqktfYkNjxfGAzzJps+0e
mfkkG4Ax5GJWHC0q5I3PKXlqSESpqooARa5bYZ1wt5iqEYPbUkt1csbsnXlZ
X1EHwZb9YYmQBEJSjOyA49jwpeetaEt//VvIlFPHp4a7QnYePSa3gH1DsKkM
NG/cZjZoh/ik5yAPD56w1/Ym+RP0y11lwpWxbpfq0iyu5RbUekD9cgXAnCvP
G29Sqt8H3C299v2dbp3utRSf+bS/ERra6XVipWjjxfkD2tgrruFIERSAGQX1
FPvS6ztH0301hUEXeA7cA4OuGK5sgbBeiRoSHE/DdbTeLiRIxbW01rqIXxzz
ItJRAby+866YRBJnl/vvauszUFNz9JpV2ZS5c+weELrkPBlUuaV0CieLkwIn
T318njOQ+cnW1cpxWPaiK/qSCBaIc6sOiVhLL4wRePu2FRe47mC4
=Gp87
-----END PGP MESSAGE-----
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@
"skp",
"avif",
"eps",
"lzh"
"lzh",
"pgp"
],
"devDependencies": {
"@types/node": "^13.1.4",
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ Returns a set of supported MIME types.
- [`avif`](https://en.wikipedia.org/wiki/AV1#AV1_Image_File_Format_(AVIF)) - AV1 Image File Format
- [`eps`](https://en.wikipedia.org/wiki/Encapsulated_PostScript) - Encapsulated PostScript
- [`lzh`](https://en.wikipedia.org/wiki/LHA_(file_format)) - LZH archive
- [`pgp`](https://en.wikipedia.org/wiki/Pretty_Good_Privacy) - Pretty Good Privacy

*Pull requests are welcome for additional commonly used file types.*

Expand Down
6 changes: 4 additions & 2 deletions supported.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ module.exports = {
'skp',
'avif',
'eps',
'lzh'
'lzh',
'pgp'
],
mimeTypes: [
'image/jpeg',
Expand Down Expand Up @@ -256,6 +257,7 @@ module.exports = {
'video/MP2P',
'application/vnd.sketchup.skp',
'image/avif',
'application/x-lzh-compressed'
'application/x-lzh-compressed',
'application/pgp-encrypted'
]
};

0 comments on commit 4a851af

Please sign in to comment.