diff --git a/bgpwtf/cccampix/pgpencryptor/gpg/gpg.go b/bgpwtf/cccampix/pgpencryptor/gpg/gpg.go index 09fcc7fa..0c0792bb 100644 --- a/bgpwtf/cccampix/pgpencryptor/gpg/gpg.go +++ b/bgpwtf/cccampix/pgpencryptor/gpg/gpg.go @@ -141,9 +141,15 @@ func (encryptor *CLIEncryptor) Finish() { } func (encryptor *CLIEncryptor) Close() { - encryptor.stdout.Close() - encryptor.stderr.Close() - encryptor.stdin.Close() + if encryptor.stdout != nil { + encryptor.stdout.Close() + } + if encryptor.stderr != nil { + encryptor.stderr.Close() + } + if encryptor.stdin != nil { + encryptor.stdin.Close() + } os.RemoveAll(encryptor.tempDir) } diff --git a/bgpwtf/cccampix/pgpencryptor/main.go b/bgpwtf/cccampix/pgpencryptor/main.go index 3d73e01d..87338b5e 100644 --- a/bgpwtf/cccampix/pgpencryptor/main.go +++ b/bgpwtf/cccampix/pgpencryptor/main.go @@ -3,10 +3,6 @@ package main import ( "context" "flag" - "github.com/golang/glog" - "github.com/lib/pq" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" "io" "time" @@ -15,6 +11,10 @@ import ( "code.hackerspace.pl/hscloud/bgpwtf/cccampix/pgpencryptor/model" pb "code.hackerspace.pl/hscloud/bgpwtf/cccampix/proto" "code.hackerspace.pl/hscloud/go/mirko" + "github.com/golang/glog" + "github.com/lib/pq" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) var ( @@ -126,11 +126,11 @@ func (s *service) Encrypt(stream pb.PGPEncryptor_EncryptServer) error { senderDone := make(chan struct{}) errors := make(chan error) enc, err := s.encryptorFactory.Get(key.Fingerprint, key.KeyData) - defer enc.Close() if err != nil { return status.Errorf(codes.Unavailable, "PGPEncryptor error while creating encryptor: %v", err) } + defer enc.Close() err = enc.WritePlainText(initialMessage.Data) if err != nil {