You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2019/10/24 16:45:17 UTC

[mynewt-artifact] 01/06: sec: Add function to get pub enc key from priv key

This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-artifact.git

commit 9d893f19ec48ada9c7f3b1210df54c873253387c
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Oct 23 12:48:13 2019 -0700

    sec: Add function to get pub enc key from priv key
    
    func (key *PrivEncKey) PubEncKey() PubEncKey
---
 sec/encrypt.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sec/encrypt.go b/sec/encrypt.go
index b63ab8d..0fc83d1 100644
--- a/sec/encrypt.go
+++ b/sec/encrypt.go
@@ -90,6 +90,12 @@ func ParsePubEncKey(keyBytes []byte) (PubEncKey, error) {
 	return parsePubKePem(keyBytes)
 }
 
+func (key *PrivEncKey) PubEncKey() PubEncKey {
+	return PubEncKey{
+		Rsa: key.Rsa.Public().(*rsa.PublicKey),
+	}
+}
+
 func (key *PubEncKey) AssertValid() {
 	if key.Rsa == nil && key.Aes == nil {
 		panic("invalid public encryption key; neither RSA nor AES")