Skip to content

Commit a384644

Browse files
committed
feat: add read-public read-private utils
Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent ab9f435 commit a384644

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

cli/util/cli.go

+26
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,32 @@ func (a *UtilArgs) BuildCommands() []*ucli.Command {
4747
},
4848
},
4949
},
50+
{
51+
Name: "read-private",
52+
Usage: "loads a private key pem and prints the peer id",
53+
Action: a.RunReadPrivatePeerId,
54+
Flags: []ucli.Flag{
55+
&ucli.StringFlag{
56+
Name: "file",
57+
Aliases: []string{"f"},
58+
Usage: "file to load pem formatted private key",
59+
Destination: &a.FilePath,
60+
},
61+
},
62+
},
63+
{
64+
Name: "read-public",
65+
Usage: "loads a public key pem and prints the peer id",
66+
Action: a.RunReadPublicPeerId,
67+
Flags: []ucli.Flag{
68+
&ucli.StringFlag{
69+
Name: "file",
70+
Aliases: []string{"f"},
71+
Usage: "file to load pem formatted public key",
72+
Destination: &a.FilePath,
73+
},
74+
},
75+
},
5076
{
5177
Name: "derive-public",
5278
Usage: "loads a private key pem and writes a public key",

cli/util/util.go

+21
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ func (a *UtilArgs) RunGeneratePrivate(_ *cli.Context) error {
5959
return nil
6060
}
6161

62+
// RunReadPublicPeerId loads a public key and prints the peer ID.
63+
func (a *UtilArgs) RunReadPublicPeerId(_ *cli.Context) error {
64+
rp, err := a.readInputFilePubKey()
65+
if err != nil {
66+
return err
67+
}
68+
_, err = os.Stdout.WriteString(rp.GetPeerID().String() + "\n")
69+
return err
70+
}
71+
72+
// RunReadPrivatePeerId loads a private key and prints the peer ID.
73+
func (a *UtilArgs) RunReadPrivatePeerId(_ *cli.Context) error {
74+
rp, err := a.readInputFilePrivKey()
75+
if err != nil {
76+
return err
77+
}
78+
_, err = os.Stdout.WriteString(rp.GetPeerID().String() + "\n")
79+
return err
80+
}
81+
6282
// RunDerivePublic derives the public key from a private pem.
6383
func (a *UtilArgs) RunDerivePublic(_ *cli.Context) error {
6484
rp, err := a.readInputFilePrivKey()
@@ -76,6 +96,7 @@ func (a *UtilArgs) RunDerivePublic(_ *cli.Context) error {
7696
return nil
7797
}
7898

99+
79100
// RunDerivePublic derives the ssh public key from a private or public pem.
80101
func (a *UtilArgs) RunDeriveSshPublic(_ *cli.Context) error {
81102
rp, err := a.readInputFilePubKey()

go.sum

-4
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 h1:Dx7Ovyv/SFnMFw
120120
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
121121
github.com/pion/datachannel v1.5.9 h1:LpIWAOYPyDrXtU+BW7X0Yt/vGtYxtXQ8ql7dFfYUVZA=
122122
github.com/pion/datachannel v1.5.9/go.mod h1:kDUuk4CU4Uxp82NH4LQZbISULkX/HtzKa4P7ldf9izE=
123-
github.com/pion/dtls/v3 v3.0.3 h1:j5ajZbQwff7Z8k3pE3S+rQ4STvKvXUdKsi/07ka+OWM=
124-
github.com/pion/dtls/v3 v3.0.3/go.mod h1:weOTUyIV4z0bQaVzKe8kpaP17+us3yAuiQsEAG1STMU=
125123
github.com/pion/dtls/v3 v3.0.4 h1:44CZekewMzfrn9pmGrj5BNnTMDCFwr+6sLH+cCuLM7U=
126124
github.com/pion/dtls/v3 v3.0.4/go.mod h1:R373CsjxWqNPf6MEkfdy3aSe9niZvL/JaKlGeFphtMg=
127125
github.com/pion/ice/v4 v4.0.2 h1:1JhBRX8iQLi0+TfcavTjPjI6GO41MFn4CeTBX+Y9h5s=
@@ -150,8 +148,6 @@ github.com/pion/transport/v3 v3.0.7 h1:iRbMH05BzSNwhILHoBoAPxoB9xQgOaJk+591KC9P1
150148
github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uPLGhhz9rwo=
151149
github.com/pion/turn/v4 v4.0.0 h1:qxplo3Rxa9Yg1xXDxxH8xaqcyGUtbHYw4QSCvmFWvhM=
152150
github.com/pion/turn/v4 v4.0.0/go.mod h1:MuPDkm15nYSklKpN8vWJ9W2M0PlyQZqYt1McGuxG7mA=
153-
github.com/pion/webrtc/v4 v4.0.1 h1:6Unwc6JzoTsjxetcAIoWH81RUM4K5dBc1BbJGcF9WVE=
154-
github.com/pion/webrtc/v4 v4.0.1/go.mod h1:SfNn8CcFxR6OUVjLXVslAQ3a3994JhyE3Hw1jAuqEto=
155151
github.com/pion/webrtc/v4 v4.0.2 h1:fBwm5/hqSUybrCWl0DDBSTDrpbkcgkqpeLmXw9CsBQA=
156152
github.com/pion/webrtc/v4 v4.0.2/go.mod h1:moylBT2A4dNoEaYBCdV1nThM3TLwRHzWszIG+eSPaqQ=
157153
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

0 commit comments

Comments
 (0)