Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
clients
python
sakia
Commits
bc0bff93
Commit
bc0bff93
authored
9 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Add forgotten file
parent
b2078f01
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/ucoinpy/documents/document.py
+45
-0
45 additions, 0 deletions
lib/ucoinpy/documents/document.py
with
45 additions
and
0 deletions
lib/ucoinpy/documents/document.py
0 → 100644
+
45
−
0
View file @
bc0bff93
import
base58
import
base64
import
re
import
logging
import
hashlib
from
..key
import
Base58Encoder
class
Document
:
re_version
=
re
.
compile
(
"
Version: ([0-9]+)
\n
"
)
re_currency
=
re
.
compile
(
"
Currency: ([^
\n
]+)
\n
"
)
re_signature
=
re
.
compile
(
"
([A-Za-z0-9+/]+(?:=|==)?)
\n
"
)
def
__init__
(
self
,
version
,
currency
,
signatures
):
self
.
version
=
version
self
.
currency
=
currency
if
signatures
:
self
.
signatures
=
[
s
for
s
in
signatures
if
s
is
not
None
]
else
:
self
.
signatures
=
[]
def
sign
(
self
,
keys
):
"""
Sign the current document.
Warning : current signatures will be replaced with the new ones.
"""
self
.
signatures
=
[]
for
key
in
keys
:
signing
=
base64
.
b64encode
(
key
.
signature
(
bytes
(
self
.
raw
(),
'
ascii
'
)))
logging
.
debug
(
"
Signature :
\n
{0}
"
.
format
(
signing
.
decode
(
"
ascii
"
)))
self
.
signatures
.
append
(
signing
.
decode
(
"
ascii
"
))
def
signed_raw
(
self
):
"""
If keys are None, returns the raw + current signatures
If keys are present, returns the raw signed by these keys
"""
raw
=
self
.
raw
()
signed
=
"
\n
"
.
join
(
self
.
signatures
)
signed_raw
=
raw
+
signed
+
"
\n
"
return
signed_raw
@property
def
sha_hash
(
self
):
return
hashlib
.
sha1
(
self
.
signed_raw
().
encode
(
"
ascii
"
)).
hexdigest
().
upper
()
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