Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
45fcd1d8
Commit
45fcd1d8
authored
6 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#78
AA dash escape cleartext
parent
358a7736
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
duniterpy/key/ascii_armor.py
+38
-7
38 additions, 7 deletions
duniterpy/key/ascii_armor.py
with
38 additions
and
7 deletions
duniterpy/key/ascii_armor.py
+
38
−
7
View file @
45fcd1d8
...
...
@@ -12,6 +12,7 @@ END_MESSAGE_HEADER = "-----END DUNITER MESSAGE-----"
BEGIN_SIGNATURE_HEADER
=
"
-----BEGIN DUNITER SIGNATURE-----
"
END_SIGNATURE_HEADER
=
"
-----END DUNITER SIGNATURE-----
"
HEADER_PREFIX
=
"
-----
"
DASH_ESCAPE_PREFIX
=
"
\x2D\x20
"
# Version field value
VERSION_FIELD_VALUE
=
"
Python Libnacl
"
+
libnacl
.
__version__
...
...
@@ -86,7 +87,6 @@ class AsciiArmor:
if
scrypt_params
is
None
:
scrypt_params
=
ScryptParams
()
# TODO: improve cleaning of spaces and tab at end of lines
# remove last newline of the message if any
message
=
message
.
strip
(
"
\n\r
"
)
...
...
@@ -117,8 +117,10 @@ class AsciiArmor:
ascii_armor_block
+=
"""
{base64_encrypted_message}
"""
.
format
(
base64_encrypted_message
=
base64_encrypted_message
.
decode
(
'
utf-8
'
))
else
:
# TODO: Dash escape cleartext
# clear text message
# remove trailing spaces
message
=
AsciiArmor
.
_remove_trailing_spaces
(
message
)
# dash escape the message
message
=
AsciiArmor
.
_dash_escape_text
(
message
)
ascii_armor_block
+=
message
+
"
\n
"
# if no signature...
...
...
@@ -135,6 +137,37 @@ class AsciiArmor:
return
ascii_armor_block
@staticmethod
def
_remove_trailing_spaces
(
text
:
str
)
->
str
:
clean_text
=
str
()
for
line
in
text
.
splitlines
():
# remove trailing spaces (0x20) and tabs (0x09)
clean_text
+=
line
.
rstrip
(
"
\x09\x20
"
)
return
clean_text
@staticmethod
def
_dash_escape_text
(
text
:
str
)
->
str
:
dash_escaped_text
=
str
()
for
line
in
text
.
splitlines
():
# add dash '-' (0x2D) and space ' ' (0x20) as prefix
dash_escaped_text
+=
DASH_ESCAPE_PREFIX
return
dash_escaped_text
@staticmethod
def
_parse_dash_escaped_line
(
dash_escaped_line
:
str
)
->
str
:
text
=
str
()
regex_dash_escape_prefix
=
compile
(
'
^
'
+
DASH_ESCAPE_PREFIX
)
# if prefixed by a dash escape prefix...
if
regex_dash_escape_prefix
.
match
(
dash_escaped_line
):
# remove dash '-' (0x2D) and space ' ' (0x20) prefix
text
+=
dash_escaped_line
[
2
:]
return
text
@staticmethod
def
_get_version_field
()
->
str
:
"""
...
...
@@ -312,14 +345,12 @@ class AsciiArmor:
cursor_status
=
ON_SIGNATURE_FIELDS
continue
else
:
# concatenate line to message content
message
+=
line
# concatenate
striped dash escaped
line to message content
message
+=
AsciiArmor
.
_parse_dash_escaped_line
(
line
)
# if we are on a signature fields zone...
if
cursor_status
==
ON_SIGNATURE_FIELDS
:
# TODO: Handle Dash escaped cleartext
# parse field
m
=
regex_fields
.
match
(
line
.
strip
())
if
m
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment