diff options
author | Wim <wim@42.be> | 2018-03-04 23:46:13 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2018-03-04 23:46:13 +0100 |
commit | 25a72113b122f984c904b24c4af23a1cba1eff45 (patch) | |
tree | f0fb7067d7c958d60ac964afa5b8d5fb79ebc339 /vendor/github.com/xordataexchange/crypt/encoding/secconf | |
parent | 79c4ad5015bd2be47b32141c6d53f0d128bf865b (diff) | |
download | matterbridge-msglm-25a72113b122f984c904b24c4af23a1cba1eff45.tar.gz matterbridge-msglm-25a72113b122f984c904b24c4af23a1cba1eff45.tar.bz2 matterbridge-msglm-25a72113b122f984c904b24c4af23a1cba1eff45.zip |
Add vendor files for spf13/viper
Diffstat (limited to 'vendor/github.com/xordataexchange/crypt/encoding/secconf')
-rw-r--r-- | vendor/github.com/xordataexchange/crypt/encoding/secconf/LICENSE | 9 | ||||
-rw-r--r-- | vendor/github.com/xordataexchange/crypt/encoding/secconf/secconf.go | 68 |
2 files changed, 77 insertions, 0 deletions
diff --git a/vendor/github.com/xordataexchange/crypt/encoding/secconf/LICENSE b/vendor/github.com/xordataexchange/crypt/encoding/secconf/LICENSE new file mode 100644 index 00000000..43846317 --- /dev/null +++ b/vendor/github.com/xordataexchange/crypt/encoding/secconf/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2014 XOR Data Exchange, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/xordataexchange/crypt/encoding/secconf/secconf.go b/vendor/github.com/xordataexchange/crypt/encoding/secconf/secconf.go new file mode 100644 index 00000000..6e94565d --- /dev/null +++ b/vendor/github.com/xordataexchange/crypt/encoding/secconf/secconf.go @@ -0,0 +1,68 @@ +// Package secconf implements secconf encoding as specified in the following +// format: +// +// base64(gpg(gzip(data))) +// +package secconf + +import ( + "bytes" + "compress/gzip" + "encoding/base64" + "io" + "io/ioutil" + + "golang.org/x/crypto/openpgp" +) + +// Deocde decodes data using the secconf codec. +func Decode(data []byte, secertKeyring io.Reader) ([]byte, error) { + decoder := base64.NewDecoder(base64.StdEncoding, bytes.NewBuffer(data)) + entityList, err := openpgp.ReadArmoredKeyRing(secertKeyring) + if err != nil { + return nil, err + } + md, err := openpgp.ReadMessage(decoder, entityList, nil, nil) + if err != nil { + return nil, err + } + gzReader, err := gzip.NewReader(md.UnverifiedBody) + if err != nil { + return nil, err + } + defer gzReader.Close() + bytes, err := ioutil.ReadAll(gzReader) + if err != nil { + return nil, err + } + return bytes, nil +} + +// Encode encodes data to a base64 encoded using the secconf codec. +// data is encrypted with all public keys found in the supplied keyring. +func Encode(data []byte, keyring io.Reader) ([]byte, error) { + entityList, err := openpgp.ReadArmoredKeyRing(keyring) + if err != nil { + return nil, err + } + buffer := new(bytes.Buffer) + encoder := base64.NewEncoder(base64.StdEncoding, buffer) + pgpWriter, err := openpgp.Encrypt(encoder, entityList, nil, nil, nil) + if err != nil { + return nil, err + } + gzWriter := gzip.NewWriter(pgpWriter) + if _, err := gzWriter.Write(data); err != nil { + return nil, err + } + if err := gzWriter.Close(); err != nil { + return nil, err + } + if err := pgpWriter.Close(); err != nil { + return nil, err + } + if err := encoder.Close(); err != nil { + return nil, err + } + return buffer.Bytes(), nil +} |