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
ad7ebf2b
Commit
ad7ebf2b
authored
5 years ago
by
Éloïs
Committed by
Éloïs
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[fix] handle pubkeys with too many leading zeros
parent
0a4c67e5
No related branches found
No related tags found
1 merge request
!10
Elois/pubkey leading 1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+4
-0
4 additions, 0 deletions
CHANGELOG.md
src/bases/b58.rs
+35
-6
35 additions, 6 deletions
src/bases/b58.rs
with
39 additions
and
6 deletions
CHANGELOG.md
+
4
−
0
View file @
ad7ebf2b
...
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
...
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] - ReleaseDate
## [Unreleased] - ReleaseDate
### Fixed
-
base58: handle base58 string with too many leading zeros (Especially the string
`11111111111111111111111111111111111111111111`
).
## [0.12.0] - 2020-03-02
## [0.12.0] - 2020-03-02
### Fixed
### Fixed
...
...
This diff is collapsed.
Click to expand it.
src/bases/b58.rs
+
35
−
6
View file @
ad7ebf2b
...
@@ -58,17 +58,20 @@ pub fn str_base58_to_32bytes(base58_data: &str) -> Result<([u8; 32], usize), Bas
...
@@ -58,17 +58,20 @@ pub fn str_base58_to_32bytes(base58_data: &str) -> Result<([u8; 32], usize), Bas
}
}
/// Create a Base58 string from a slice of bytes.
/// Create a Base58 string from a slice of bytes.
pub
fn
bytes_to_str_base58
(
bytes
:
&
[
u8
],
mut
count_leading_1
:
usize
)
->
String
{
pub
fn
bytes_to_str_base58
(
bytes
:
&
[
u8
],
count_leading_1
:
usize
)
->
String
{
let
mut
str_base58
=
String
::
new
();
let
mut
str_base58
=
String
::
new
();
let
bytes
=
&
bytes
[
count_leading_1
..
];
let
mut
remaining_leading_1
=
count_leading_1
;
while
remaining_leading_1
>
0
{
remaining_leading_1
-=
1
;
str_base58
.push
(
'1'
);
}
if
count_leading_1
>=
32
{
return
str_base58
;
}
let
bytes
=
if
count_leading_1
==
0
&&
!
bytes
.is_empty
()
&&
bytes
[
0
]
==
0
{
let
bytes
=
if
count_leading_1
==
0
&&
!
bytes
.is_empty
()
&&
bytes
[
0
]
==
0
{
&
bytes
[
1
..
]
&
bytes
[
1
..
]
}
else
{
}
else
{
while
count_leading_1
>
0
{
count_leading_1
-=
1
;
str_base58
.push
(
'1'
);
}
&
bytes
[
count_leading_1
..
]
&
bytes
[
count_leading_1
..
]
};
};
...
@@ -82,8 +85,34 @@ mod tests {
...
@@ -82,8 +85,34 @@ mod tests {
use
super
::
*
;
use
super
::
*
;
#[test]
fn
test_base_58_str_with_only_1
()
->
Result
<
(),
BaseConvertionError
>
{
let
base58str
=
"11111111111111111111111111111111111111111111"
;
let
(
bytes
,
count_leading_1
)
=
str_base58_to_32bytes
(
base58str
)
?
;
println!
(
"{:?}"
,
bytes
);
assert_eq!
(
base58str
,
&
bytes_to_str_base58
(
&
bytes
[
..
],
count_leading_1
),);
Ok
(())
}
#[test]
#[test]
fn
test_base_58_str_with_leading_1
()
->
Result
<
(),
BaseConvertionError
>
{
fn
test_base_58_str_with_leading_1
()
->
Result
<
(),
BaseConvertionError
>
{
let
base58str
=
"13fn6X3XWVgshHTgS8beZMo9XiyScx6MB6yPsBB5ZBia"
;
let
(
bytes
,
count_leading_1
)
=
str_base58_to_32bytes
(
base58str
)
?
;
println!
(
"{:?}"
,
bytes
);
assert_eq!
(
base58str
,
&
bytes_to_str_base58
(
&
bytes
[
..
],
count_leading_1
),);
Ok
(())
}
#[test]
fn
test_other_base_58_str_with_leading_1
()
->
Result
<
(),
BaseConvertionError
>
{
let
base58str
=
"1V27SH9TiVEDs8TWFPydpRKxhvZari7wjGwQnPxMnkr"
;
let
base58str
=
"1V27SH9TiVEDs8TWFPydpRKxhvZari7wjGwQnPxMnkr"
;
let
(
bytes
,
count_leading_1
)
=
str_base58_to_32bytes
(
base58str
)
?
;
let
(
bytes
,
count_leading_1
)
=
str_base58_to_32bytes
(
base58str
)
?
;
...
...
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