Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/ascii-armored' of https://github.com/scop/pygments …
…into scop-feat/ascii-armored
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
pygments.lexers.asc | ||
~~~~~~~~~~~~~~~~~~~ | ||
Lexer for various ASCII armored files. | ||
:copyright: Copyright 2021 by the Pygments team, see AUTHORS. | ||
:license: BSD, see LICENSE for details. | ||
""" | ||
import re | ||
|
||
from pygments.lexer import RegexLexer, bygroups | ||
from pygments.token import Comment, Generic, Name, Operator, String, Whitespace | ||
|
||
__all__ = ['AscLexer'] | ||
|
||
|
||
class AscLexer(RegexLexer): | ||
""" | ||
Lexer for ASCII armored files, containing `-----BEGIN/END ...-----` wrapped base64 data. | ||
.. versionadded:: 2.10 | ||
""" | ||
name = 'ASCII armored' | ||
aliases = ['asc', 'pem'] | ||
filenames = [ | ||
'*.asc', # PGP; *.gpg, *.pgp, and *.sig too, but those can be binary | ||
'*.pem', # X.509; *.cer, *.crt, *.csr, and key etc too, but those can be binary | ||
'id_dsa', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk', 'id_rsa', # SSH private keys | ||
] | ||
mimetypes = ['application/pgp-keys', 'application/pgp-encrypted', 'application/pgp-signature'] | ||
|
||
flags = re.MULTILINE | ||
|
||
tokens = { | ||
'root': [ | ||
(r'\s+', Whitespace), | ||
(r'^-----BEGIN [^\n]+-----$', Generic.Heading, 'data'), | ||
(r'\S+', Comment), | ||
], | ||
'data': [ | ||
(r'\s+', Whitespace), | ||
(r'^([^:]+)(:)([ \t]+)(.*)', bygroups(Name.Attribute, Operator, Whitespace, String)), | ||
(r'^-----END [^\n]+-----$', Generic.Heading, 'root'), | ||
(r'\S+', String), | ||
], | ||
} | ||
|
||
def analyse_text(text): | ||
if re.search(r'^-----BEGIN [^\n]+-----\r?\n', text): | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-----BEGIN EC PRIVATE KEY----- | ||
Proc-Type: 4,ENCRYPTED | ||
DEK-Info: AES-128-CBC,IVIVIVIVIVIVIVIVIVIVIVIVIVIVIVIV | ||
|
||
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ | ||
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ | ||
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ | ||
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq= | ||
-----END EC PRIVATE KEY----- |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.