Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
64f7ed04
Commit
64f7ed04
authored
5 years ago
by
Caio
Committed by
Bastian Köcher
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Implement Copy, Deref and FromStr to (ed25519|sr25519)::Public (#3998)
parent
e1b6f68f
Branches
gh-readonly-queue/master/pr-4481-3399bc09c60ea7de8766fef760a04c5a6b9ada15
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/core/primitives/src/ed25519.rs
+19
-1
19 additions, 1 deletion
substrate/core/primitives/src/ed25519.rs
substrate/core/primitives/src/sr25519.rs
+19
-1
19 additions, 1 deletion
substrate/core/primitives/src/sr25519.rs
with
38 additions
and
2 deletions
substrate/core/primitives/src/ed25519.rs
+
19
−
1
View file @
64f7ed04
...
...
@@ -38,6 +38,7 @@ use crate::crypto::Ss58Codec;
use
serde
::{
de
,
Serializer
,
Serialize
,
Deserializer
,
Deserialize
};
use
crate
::{
crypto
::{
Public
as
TraitPublic
,
UncheckedFrom
,
CryptoType
,
Derive
}};
use
runtime_interface
::
pass_by
::
PassByInner
;
use
rstd
::
ops
::
Deref
;
/// A secret seed. It's not called a "secret key" because ring doesn't expose the secret keys
/// of the key pair (yeah, dumb); as such we're forced to remember the seed manually if we
...
...
@@ -47,7 +48,7 @@ type Seed = [u8; 32];
/// A public key.
#[cfg_attr(feature
=
"full_crypto"
,
derive(Hash))]
#[derive(PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Encode,
Decode,
Default,
PassByInner)]
#[derive(PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Encode,
Decode,
Default,
PassByInner)]
pub
struct
Public
(
pub
[
u8
;
32
]);
/// A key pair.
...
...
@@ -83,6 +84,14 @@ impl AsMut<[u8]> for Public {
}
}
impl
Deref
for
Public
{
type
Target
=
[
u8
];
fn
deref
(
&
self
)
->
&
Self
::
Target
{
&
self
.0
}
}
impl
rstd
::
convert
::
TryFrom
<&
[
u8
]
>
for
Public
{
type
Error
=
();
...
...
@@ -116,6 +125,15 @@ impl From<Public> for H256 {
}
}
#[cfg(feature
=
"std"
)]
impl
std
::
str
::
FromStr
for
Public
{
type
Err
=
crate
::
crypto
::
PublicError
;
fn
from_str
(
s
:
&
str
)
->
Result
<
Self
,
Self
::
Err
>
{
Self
::
from_ss58check
(
s
)
}
}
impl
UncheckedFrom
<
[
u8
;
32
]
>
for
Public
{
fn
unchecked_from
(
x
:
[
u8
;
32
])
->
Self
{
Public
::
from_raw
(
x
)
...
...
This diff is collapsed.
Click to expand it.
substrate/core/primitives/src/sr25519.rs
+
19
−
1
View file @
64f7ed04
...
...
@@ -40,6 +40,7 @@ use crate::crypto::Ss58Codec;
use
crate
::{
crypto
::{
Public
as
TraitPublic
,
UncheckedFrom
,
CryptoType
,
Derive
}};
use
crate
::
hash
::{
H256
,
H512
};
use
codec
::{
Encode
,
Decode
};
use
rstd
::
ops
::
Deref
;
#[cfg(feature
=
"std"
)]
use
serde
::{
de
,
Deserialize
,
Deserializer
,
Serialize
,
Serializer
};
...
...
@@ -53,7 +54,7 @@ const SIGNING_CTX: &[u8] = b"substrate";
/// An Schnorrkel/Ristretto x25519 ("sr25519") public key.
#[cfg_attr(feature
=
"full_crypto"
,
derive(Hash))]
#[derive(PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Encode,
Decode,
Default,
PassByInner)]
#[derive(PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Encode,
Decode,
Default,
PassByInner)]
pub
struct
Public
(
pub
[
u8
;
32
]);
/// An Schnorrkel/Ristretto x25519 ("sr25519") key pair.
...
...
@@ -89,6 +90,14 @@ impl AsMut<[u8]> for Public {
}
}
impl
Deref
for
Public
{
type
Target
=
[
u8
];
fn
deref
(
&
self
)
->
&
Self
::
Target
{
&
self
.0
}
}
impl
From
<
Public
>
for
[
u8
;
32
]
{
fn
from
(
x
:
Public
)
->
[
u8
;
32
]
{
x
.0
...
...
@@ -101,6 +110,15 @@ impl From<Public> for H256 {
}
}
#[cfg(feature
=
"std"
)]
impl
std
::
str
::
FromStr
for
Public
{
type
Err
=
crate
::
crypto
::
PublicError
;
fn
from_str
(
s
:
&
str
)
->
Result
<
Self
,
Self
::
Err
>
{
Self
::
from_ss58check
(
s
)
}
}
impl
rstd
::
convert
::
TryFrom
<&
[
u8
]
>
for
Public
{
type
Error
=
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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