Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dup-crypto-rs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
libs
dup-crypto-rs
Commits
1a6bc8fe
Commit
1a6bc8fe
authored
5 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[fix] ed25519:pubkey don't have min size. empty pubkey must be supported
parent
b1292d6b
No related branches found
No related tags found
1 merge request
!6
[fix] ed25519:pubkey don't have min size. empty pubkey must be supported
Pipeline
#8236
passed
5 years ago
Stage: fmt
Stage: tests
Stage: quality
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+5
-0
5 additions, 0 deletions
CHANGELOG.md
src/bases/b58.rs
+6
-1
6 additions, 1 deletion
src/bases/b58.rs
src/keys/ed25519.rs
+9
-12
9 additions, 12 deletions
src/keys/ed25519.rs
src/keys/mod.rs
+4
-14
4 additions, 14 deletions
src/keys/mod.rs
with
24 additions
and
27 deletions
CHANGELOG.md
+
5
−
0
View file @
1a6bc8fe
# Changelog
# Changelog
All notable changes to this project will be documented in this file.
All notable changes to this project will be documented in this file.
The format is based on
[
Keep a Changelog
](
https://keepachangelog.com/en/1.0.0/
)
,
The format is based on
[
Keep a Changelog
](
https://keepachangelog.com/en/1.0.0/
)
,
...
@@ -8,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
...
@@ -8,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] - ReleaseDate
## [Unreleased] - ReleaseDate
### Fixed
-
ed25519: public key don't have min size. empty public key must be supported.
## [0.11.0] - 2020-02-29
## [0.11.0] - 2020-02-29
### Changed
### Changed
...
...
This diff is collapsed.
Click to expand it.
src/bases/b58.rs
+
6
−
1
View file @
1a6bc8fe
...
@@ -25,7 +25,12 @@ pub trait ToBase58 {
...
@@ -25,7 +25,12 @@ pub trait ToBase58 {
/// Create an array of 32 bytes from a Base58 string.
/// Create an array of 32 bytes from a Base58 string.
pub
fn
str_base58_to_32bytes
(
base58_data
:
&
str
)
->
Result
<
([
u8
;
32
],
usize
),
BaseConvertionError
>
{
pub
fn
str_base58_to_32bytes
(
base58_data
:
&
str
)
->
Result
<
([
u8
;
32
],
usize
),
BaseConvertionError
>
{
match
bs58
::
decode
(
base58_data
)
.into_vec
()
{
let
mut
source
=
base58_data
;
while
!
source
.is_empty
()
&&
&
source
[
0
..
1
]
==
"1"
{
source
=
&
source
[
1
..
];
}
match
bs58
::
decode
(
source
)
.into_vec
()
{
Ok
(
result
)
=>
{
Ok
(
result
)
=>
{
let
len
=
result
.len
();
let
len
=
result
.len
();
if
len
<=
32
{
if
len
<=
32
{
...
...
This diff is collapsed.
Click to expand it.
src/keys/ed25519.rs
+
9
−
12
View file @
1a6bc8fe
...
@@ -45,8 +45,6 @@ use zeroize::Zeroize;
...
@@ -45,8 +45,6 @@ use zeroize::Zeroize;
/// Maximal size of a public key in bytes
/// Maximal size of a public key in bytes
pub
const
PUBKEY_SIZE_IN_BYTES
:
usize
=
32
;
pub
const
PUBKEY_SIZE_IN_BYTES
:
usize
=
32
;
/// constl size of a public key in bytes
pub
const
PUBKEY_MIN_SIZE_IN_BYTES
:
usize
=
31
;
/// constf a signature in bytes
/// constf a signature in bytes
pub
const
SIG_SIZE_IN_BYTES
:
usize
=
64
;
pub
const
SIG_SIZE_IN_BYTES
:
usize
=
64
;
...
@@ -168,7 +166,7 @@ impl Default for PublicKey {
...
@@ -168,7 +166,7 @@ impl Default for PublicKey {
fn
default
()
->
Self
{
fn
default
()
->
Self
{
PublicKey
{
PublicKey
{
datas
:
[
0u8
;
32
],
datas
:
[
0u8
;
32
],
len
:
32
,
len
:
0
,
}
}
}
}
}
}
...
@@ -183,7 +181,7 @@ impl TryFrom<&[u8]> for PublicKey {
...
@@ -183,7 +181,7 @@ impl TryFrom<&[u8]> for PublicKey {
type
Error
=
PubkeyFromBytesError
;
type
Error
=
PubkeyFromBytesError
;
fn
try_from
(
bytes
:
&
[
u8
])
->
Result
<
Self
,
Self
::
Error
>
{
fn
try_from
(
bytes
:
&
[
u8
])
->
Result
<
Self
,
Self
::
Error
>
{
if
bytes
.len
()
>
PUBKEY_SIZE_IN_BYTES
||
bytes
.len
()
<
PUBKEY_MIN_SIZE_IN_BYTES
{
if
bytes
.len
()
>
PUBKEY_SIZE_IN_BYTES
{
Err
(
PubkeyFromBytesError
::
InvalidBytesLen
{
Err
(
PubkeyFromBytesError
::
InvalidBytesLen
{
expected
:
PUBKEY_SIZE_IN_BYTES
,
expected
:
PUBKEY_SIZE_IN_BYTES
,
found
:
bytes
.len
(),
found
:
bytes
.len
(),
...
@@ -224,14 +222,7 @@ impl super::PublicKey for PublicKey {
...
@@ -224,14 +222,7 @@ impl super::PublicKey for PublicKey {
#[inline]
#[inline]
fn
from_base58
(
base58_data
:
&
str
)
->
Result
<
Self
,
BaseConvertionError
>
{
fn
from_base58
(
base58_data
:
&
str
)
->
Result
<
Self
,
BaseConvertionError
>
{
let
(
datas
,
len
)
=
b58
::
str_base58_to_32bytes
(
base58_data
)
?
;
let
(
datas
,
len
)
=
b58
::
str_base58_to_32bytes
(
base58_data
)
?
;
if
len
<
PUBKEY_MIN_SIZE_IN_BYTES
{
Ok
(
PublicKey
{
datas
,
len
})
Err
(
BaseConvertionError
::
InvalidLength
{
expected
:
PUBKEY_SIZE_IN_BYTES
,
found
:
len
,
})
}
else
{
Ok
(
PublicKey
{
datas
,
len
})
}
}
}
fn
to_bytes_vector
(
&
self
)
->
Vec
<
u8
>
{
fn
to_bytes_vector
(
&
self
)
->
Vec
<
u8
>
{
...
@@ -495,6 +486,12 @@ mod tests {
...
@@ -495,6 +486,12 @@ mod tests {
);
);
}
}
#[test]
fn
test_pubkey_111_from_base58
()
{
let
public58
=
"11111111111111111111111111111111111111111111"
;
let
_
=
unwrap!
(
super
::
PublicKey
::
from_base58
(
public58
));
}
#[test]
#[test]
fn
base58_public_key
()
{
fn
base58_public_key
()
{
let
public58
=
"DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV"
;
let
public58
=
"DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV"
;
...
...
This diff is collapsed.
Click to expand it.
src/keys/mod.rs
+
4
−
14
View file @
1a6bc8fe
...
@@ -508,10 +508,7 @@ mod tests {
...
@@ -508,10 +508,7 @@ mod tests {
#[test]
#[test]
fn
pubkey
()
{
fn
pubkey
()
{
let
pubkey_default
=
PubKey
::
default
();
let
pubkey_default
=
PubKey
::
default
();
let
pubkey_bytes
=
[
let
pubkey_bytes
=
[];
0u8
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
];
let
pubkey
=
PubKey
::
Ed25519
(
unwrap!
(
ed25519
::
PublicKey
::
try_from
(
&
pubkey_bytes
[
..
])));
let
pubkey
=
PubKey
::
Ed25519
(
unwrap!
(
ed25519
::
PublicKey
::
try_from
(
&
pubkey_bytes
[
..
])));
assert_eq!
(
pubkey_default
,
pubkey
);
assert_eq!
(
pubkey_default
,
pubkey
);
...
@@ -522,14 +519,14 @@ mod tests {
...
@@ -522,14 +519,14 @@ mod tests {
);
);
assert_eq!
(
pubkey
.size_in_bytes
(),
ed25519
::
PUBKEY_SIZE_IN_BYTES
+
3
);
assert_eq!
(
pubkey
.size_in_bytes
(),
ed25519
::
PUBKEY_SIZE_IN_BYTES
+
3
);
assert_eq!
(
pubkey_str_b58
,
format!
(
"{}"
,
pubkey
));
assert_eq!
(
""
,
&
format!
(
"{}"
,
pubkey
));
assert_eq!
(
KeysAlgo
::
Ed25519
,
pubkey
.algo
());
assert_eq!
(
KeysAlgo
::
Ed25519
,
pubkey
.algo
());
assert_eq!
(
KeysAlgo
::
Schnorr
,
PubKey
::
Schnorr
()
.algo
());
assert_eq!
(
KeysAlgo
::
Schnorr
,
PubKey
::
Schnorr
()
.algo
());
assert_eq!
(
pubkey_bytes
.to_vec
(),
pubkey
.to_bytes_vector
());
assert_eq!
(
pubkey_bytes
.to_vec
(),
pubkey
.to_bytes_vector
());
assert_eq!
(
pubkey_str_b58
,
pubkey
.to_base58
());
assert_eq!
(
""
,
&
pubkey
.to_base58
());
assert_eq!
(
assert_eq!
(
Err
(
SigError
::
InvalidSig
),
Err
(
SigError
::
InvalidSig
),
...
@@ -718,13 +715,6 @@ mod tests {
...
@@ -718,13 +715,6 @@ mod tests {
#[test]
#[test]
fn
pubkey_from_bytes
()
{
fn
pubkey_from_bytes
()
{
assert_eq!
(
Err
(
PubkeyFromBytesError
::
InvalidBytesLen
{
expected
:
ed25519
::
PUBKEY_SIZE_IN_BYTES
,
found
:
2
,
}),
PubKey
::
from_bytes
(
&
[
0u8
,
1
]),
);
assert_eq!
(
assert_eq!
(
Err
(
PubkeyFromBytesError
::
InvalidBytesLen
{
Err
(
PubkeyFromBytesError
::
InvalidBytesLen
{
expected
:
ed25519
::
PUBKEY_SIZE_IN_BYTES
,
expected
:
ed25519
::
PUBKEY_SIZE_IN_BYTES
,
...
@@ -737,7 +727,7 @@ mod tests {
...
@@ -737,7 +727,7 @@ mod tests {
);
);
assert_eq!
(
assert_eq!
(
Ok
(
PubKey
::
Ed25519
(
ed25519
::
PublicKey
::
default
())),
Ok
(
PubKey
::
Ed25519
(
ed25519
::
PublicKey
::
default
())),
PubKey
::
from_bytes
(
&
[
0u8
;
32
]),
PubKey
::
from_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