Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
crypto
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xx network
crypto
Commits
5c6b6dfd
Commit
5c6b6dfd
authored
Sep 8, 2022
by
David Stainton
Browse files
Options
Downloads
Patches
Plain Diff
Bytes use 32 bit int and add explanatory docstring
parent
257b7f27
No related branches found
No related tags found
2 merge requests
!23
Channels Implementation
,
!21
Add PublicKey's Bytes and FromBytes + tests
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
signature/rsa/rsa.go
+8
-4
8 additions, 4 deletions
signature/rsa/rsa.go
with
8 additions
and
4 deletions
signature/rsa/rsa.go
+
8
−
4
View file @
5c6b6dfd
...
@@ -131,18 +131,22 @@ func (p *PrivateKey) GetE() int {
...
@@ -131,18 +131,22 @@ func (p *PrivateKey) GetE() int {
}
}
// Bytes returns the PublicKey as a byte slice.
// Bytes returns the PublicKey as a byte slice.
// The first 4 bytes are the exponent (E) as a 4 byte big
// endian integer, followed by the modulus (N) as a big.Int
// in Bytes format. We should the 32 bit integer for E
// because it should be big enough.
func
(
p
*
PublicKey
)
Bytes
()
[]
byte
{
func
(
p
*
PublicKey
)
Bytes
()
[]
byte
{
buf
:=
make
([]
byte
,
8
)
buf
:=
make
([]
byte
,
4
)
binary
.
BigEndian
.
PutUint
64
(
buf
,
uint
64
(
p
.
GetE
()))
binary
.
BigEndian
.
PutUint
32
(
buf
,
uint
32
(
p
.
GetE
()))
return
append
(
buf
,
p
.
PublicKey
.
N
.
Bytes
()
...
)
return
append
(
buf
,
p
.
PublicKey
.
N
.
Bytes
()
...
)
}
}
// FromBytes loads the given byte slice into the PublicKey.
// FromBytes loads the given byte slice into the PublicKey.
func
(
p
*
PublicKey
)
FromBytes
(
b
[]
byte
)
error
{
func
(
p
*
PublicKey
)
FromBytes
(
b
[]
byte
)
error
{
e
:=
binary
.
BigEndian
.
Uint
64
(
b
[
:
8
])
e
:=
binary
.
BigEndian
.
Uint
32
(
b
[
:
4
])
p
.
E
=
int
(
e
)
p
.
E
=
int
(
e
)
p
.
N
=
new
(
big
.
Int
)
p
.
N
=
new
(
big
.
Int
)
p
.
N
.
SetBytes
(
b
[
8
:
])
p
.
N
.
SetBytes
(
b
[
4
:
])
return
nil
return
nil
}
}
...
...
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