From 08433db912d0b57488a5b98ecf298d9e6ea9a141 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 3 Feb 2017 19:18:43 -0800 Subject: [PATCH] creating new string key Init --- standardricochetservice.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/standardricochetservice.go b/standardricochetservice.go index a3688e4..1f404e8 100644 --- a/standardricochetservice.go +++ b/standardricochetservice.go @@ -22,21 +22,26 @@ type StandardRicochetService struct { // Init initializes a StandardRicochetService with the cryptographic key given // by filename. -func (srs *StandardRicochetService) Init(filename string) error { - srs.ricochet = new(Ricochet) - srs.ricochet.Init() - +func (srs *StandardRicochetService) InitFromKeyFile(filename string) error { pemData, err := ioutil.ReadFile(filename) if err != nil { return errors.New("Could not setup ricochet service: could not read private key") } + return srs.InitFromKey(pemData) +} + +// Init initializes a StandardRicochetService with the cryptographic key +func (srs *StandardRicochetService) InitFromKey(pemData []byte) error { + srs.ricochet = new(Ricochet) + srs.ricochet.Init() block, _ := pem.Decode(pemData) if block == nil || block.Type != "RSA PRIVATE KEY" { return errors.New("Could not setup ricochet service: no valid PEM data found") } + var err error srs.privateKey, err = x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { return errors.New("Could not setup ricochet service: could not parse private key")