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
e0b2f0dd
Commit
e0b2f0dd
authored
12 years ago
by
Donald Stufft
Browse files
Options
Downloads
Patches
Plain Diff
Document the PyNaCl encoding system
parent
fc42dee0
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
docs/encoding.rst
+58
-0
58 additions, 0 deletions
docs/encoding.rst
docs/index.rst
+9
-0
9 additions, 0 deletions
docs/index.rst
docs/signing.rst
+3
-4
3 additions, 4 deletions
docs/signing.rst
nacl/signing.py
+5
-6
5 additions, 6 deletions
nacl/signing.py
with
75 additions
and
10 deletions
docs/encoding.rst
0 → 100644
+
58
−
0
View file @
e0b2f0dd
Encoders
========
PyNaCl supports a simple method of encoding and decoding messages in different
formats. Encoders are simple classes with staticmethods that encode/decode and
are typically passed as a keyword argument `encoder` to various methods.
For example you can generate a signing key and encode it in hex with:
.. code:: python
hex_key = nacl.signing.SigningKey.generate().encode(encoder=nacl.encoding.HexEncoder)
Then you can later decode it from hex:
.. code:: python
signing_key = nacl.signing.SigningKey(hex_key, encoder=nacl.encoding.HexEncoder)
Built in Encoders
-----------------
.. autoclass:: nacl.encoding.RawEncoder
:members:
.. autoclass:: nacl.encoding.HexEncoder
:members:
.. autoclass:: nacl.encoding.Base16Encoder
:members:
.. autoclass:: nacl.encoding.Base32Encoder
:members:
.. autoclass:: nacl.encoding.Base64Encoder
:members:
Defining your own Encoder
-------------------------
Defining your own encoder is easy. Each encoder is simply a class with 2 static
methods. For example here is the hex encoder:
.. code:: python
import binascii
class HexEncoder(object):
@staticmethod
def encode(data):
return binascii.hexlify(data)
@staticmethod
def decode(data):
return binascii.unhexlify(data)
This diff is collapsed.
Click to expand it.
docs/index.rst
+
9
−
0
View file @
e0b2f0dd
...
...
@@ -9,6 +9,15 @@ Contents:
signing
Support Features
----------------
.. toctree::
:maxdepth: 2
encoding
Api Documentation
-----------------
...
...
This diff is collapsed.
Click to expand it.
docs/signing.rst
+
3
−
4
View file @
e0b2f0dd
...
...
@@ -19,7 +19,7 @@ Signer's perspective (:class:`~nacl.signing.SigningKey`)
.. code:: python
import
binascii
import
nacl.encoding
import nacl.signing
# Generate a new random signing key
...
...
@@ -32,17 +32,16 @@ Signer's perspective (:class:`~nacl.signing.SigningKey`)
verify_key = signing_key.verify_key
# Serialize the verify key to send it to a third party
binascii.hexlify(bytes(verify_key)
)
verify_key_hex = verify_key.encode(encoder=nacl.encoding.HexEncoder
)
Verifier's perspective (:class:`~nacl.signing.VerifyKey`)
.. code:: python
import binascii
import nacl.signing
# Create a VerifyKey object from a hex serialized public key
verify_key = nacl.signing.VerifyKey(
binascii.unhexlify(verify_key_hex)
)
verify_key = nacl.signing.VerifyKey(
verify_key_hex, encoder=nacl.encoding.HexEncoder
)
# Check the validity of a message's signature
# Will raise nacl.signing.BadSignatureError if the signature check fails
...
...
This diff is collapsed.
Click to expand it.
nacl/signing.py
+
5
−
6
View file @
e0b2f0dd
...
...
@@ -47,7 +47,7 @@ class VerifyKey(encoding.Encodable, six.StringFixer, object):
signatures.
:param key: [:class:`bytes`] Serialized Ed25519 public key
:param encod
ing: [:class:`str`] The encoding that the key is encoded with
:param encod
er: A class that is able to decode the `key`
"""
def
__init__
(
self
,
key
,
encoder
=
encoding
.
RawEncoder
):
...
...
@@ -73,8 +73,8 @@ class VerifyKey(encoding.Encodable, six.StringFixer, object):
signature and message concated together.
:param signature: [:class:`bytes`] If an unsigned message is given for
smessage then the detached signature must be provded.
:param encod
ing: [:class:`str`] The encoding that
the secret message
and
signature
is encoded with
.
:param encod
er: A class that is able to decode
the secret message
and
signature.
:rtype: :class:`bytes`
"""
if
signature
is
not
None
:
...
...
@@ -107,7 +107,7 @@ class SigningKey(encoding.Encodable, six.StringFixer, object):
masquerade as you.
:param seed: [:class:`bytes`] Random 32-byte value (i.e. private key)
:param encod
ing: [:class:`str`] The encoding that the seed is encoded with
:param encod
er: A class that is able to decode the seed
:ivar: verify_key: [:class:`~nacl.signing.VerifyKey`] The verify
(i.e. public) key that corresponds with this signing key.
...
...
@@ -155,8 +155,7 @@ class SigningKey(encoding.Encodable, six.StringFixer, object):
Sign a message using this key.
:param message: [:class:`bytes`] The data to be signed.
:param encoding: [:class:`str`] The encoding to encode the signed
message with.
:param encoder: A class that is used to encode the signed message.
:rtype: :class:`~nacl.signing.SignedMessage`
"""
sm
=
nacl
.
ffi
.
new
(
"
unsigned char[]
"
,
len
(
message
)
+
nacl
.
lib
.
crypto_sign_BYTES
)
...
...
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