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")