Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
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
nodes
typescript
duniter
Commits
dfc43543
Commit
dfc43543
authored
4 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[ref] dbs: DunpNodeIdV1Db must be indexed by pubkey
parent
ce88f841
No related branches found
No related tags found
1 merge request
!1372
[ref] dbs: DunpNodeIdV1Db must be indexed by pubkey
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
rust-libs/duniter-dbs/src/keys/dunp_node_id.rs
+20
-4
20 additions, 4 deletions
rust-libs/duniter-dbs/src/keys/dunp_node_id.rs
with
20 additions
and
4 deletions
rust-libs/duniter-dbs/src/keys/dunp_node_id.rs
+
20
−
4
View file @
dfc43543
...
@@ -26,24 +26,24 @@ pub struct DunpNodeIdV1Db([u8; 37]); // uuid ++ pubkey
...
@@ -26,24 +26,24 @@ pub struct DunpNodeIdV1Db([u8; 37]); // uuid ++ pubkey
impl
DunpNodeIdV1Db
{
impl
DunpNodeIdV1Db
{
pub
fn
new
(
uuid
:
u32
,
pubkey
:
PublicKey
)
->
Self
{
pub
fn
new
(
uuid
:
u32
,
pubkey
:
PublicKey
)
->
Self
{
let
mut
buffer
=
uninit_array!
[
u8
;
37
];
let
mut
buffer
=
uninit_array!
[
u8
;
37
];
let
(
uuid
_buffer
,
pubkey
_buffer
)
=
buffer
.as_out
()
.split_at_out
(
4
);
let
(
pubkey
_buffer
,
uuid
_buffer
)
=
buffer
.as_out
()
.split_at_out
(
33
);
uuid_buffer
.copy_from_slice
(
&
uuid
.to_be_bytes
()[
..
]);
pubkey_buffer
.copy_from_slice
(
pubkey
.as_ref
());
pubkey_buffer
.copy_from_slice
(
pubkey
.as_ref
());
uuid_buffer
.copy_from_slice
(
&
uuid
.to_be_bytes
()[
..
]);
Self
(
unsafe
{
std
::
mem
::
transmute
(
buffer
)
})
Self
(
unsafe
{
std
::
mem
::
transmute
(
buffer
)
})
}
}
pub
fn
get_uuid
(
&
self
)
->
u32
{
pub
fn
get_uuid
(
&
self
)
->
u32
{
let
mut
buffer
=
uninit_array!
[
u8
;
4
];
let
mut
buffer
=
uninit_array!
[
u8
;
4
];
buffer
.as_out
()
.copy_from_slice
(
&
self
.0
[
..
4
]);
buffer
.as_out
()
.copy_from_slice
(
&
self
.0
[
33
..
]);
u32
::
from_be_bytes
(
unsafe
{
std
::
mem
::
transmute
(
buffer
)
})
u32
::
from_be_bytes
(
unsafe
{
std
::
mem
::
transmute
(
buffer
)
})
}
}
pub
fn
get_pubkey
(
&
self
)
->
PublicKey
{
pub
fn
get_pubkey
(
&
self
)
->
PublicKey
{
let
mut
buffer
=
uninit_array!
[
u8
;
33
];
let
mut
buffer
=
uninit_array!
[
u8
;
33
];
buffer
.as_out
()
.copy_from_slice
(
&
self
.0
[
4
..
]);
buffer
.as_out
()
.copy_from_slice
(
&
self
.0
[
..
33
]);
let
bytes
:
[
u8
;
33
]
=
unsafe
{
std
::
mem
::
transmute
(
buffer
)
};
let
bytes
:
[
u8
;
33
]
=
unsafe
{
std
::
mem
::
transmute
(
buffer
)
};
PublicKey
::
try_from
(
&
bytes
[
..
])
.unwrap_or_else
(|
_
|
unreachable!
())
PublicKey
::
try_from
(
&
bytes
[
..
])
.unwrap_or_else
(|
_
|
unreachable!
())
...
@@ -93,3 +93,19 @@ impl ExplorableKey for DunpNodeIdV1Db {
...
@@ -93,3 +93,19 @@ impl ExplorableKey for DunpNodeIdV1Db {
Ok
(
self
.to_string
())
Ok
(
self
.to_string
())
}
}
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
#[test]
fn
test_serde
()
{
let
node_id
=
DunpNodeIdV1Db
::
new
(
42
,
PublicKey
::
default
());
assert_eq!
(
node_id
.get_uuid
(),
42
);
assert_eq!
(
node_id
.get_pubkey
(),
PublicKey
::
default
());
let
mut
node_id_
=
DunpNodeIdV1Db
([
0u8
;
37
]);
node_id_
.0
[
32
]
=
32
;
node_id_
.0
[
36
]
=
42
;
assert_eq!
(
node_id_
,
node_id
)
}
}
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