Minor: spelling and typos

This commit is contained in:
Jakub Lehotsky 2018-09-19 11:52:14 +02:00
parent 97e70855b8
commit d005dca0a4
9 changed files with 65 additions and 74 deletions

View file

@ -2,13 +2,13 @@ package armor
import ( import (
"bytes" "bytes"
"io/ioutil"
"golang.org/x/crypto/openpgp/armor"
"proton/pmcrypto/internal"
"golang.org/x/crypto/openpgp/clearsign"
"errors" "errors"
"golang.org/x/crypto/openpgp/armor"
"golang.org/x/crypto/openpgp/clearsign"
"golang.org/x/crypto/openpgp/packet" "golang.org/x/crypto/openpgp/packet"
"io" "io"
"io/ioutil"
"proton/pmcrypto/internal"
"proton/pmcrypto/models" "proton/pmcrypto/models"
) )
@ -32,9 +32,9 @@ func ArmorWithType(input []byte, armorType string) (string, error) {
return b.String(), nil return b.String(), nil
} }
// UnArmor an armored key to bytes key // Unarmor an armored key to bytes key
func UnArmor(input string) ([]byte, error) { func Unarmor(input string) ([]byte, error) {
b, err := internal.UnArmor(input) b, err := internal.Unarmor(input)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -50,14 +50,12 @@ func ReadClearSignedMessage(signedMessage string) (string, error) {
return string(modulusBlock.Bytes), nil return string(modulusBlock.Bytes), nil
} }
//SeparateKeyAndData ... //SeparateKeyAndData ...
func SplitArmor(encrypted string) (*models.EncryptedSplit, error) { func SplitArmor(encrypted string) (*models.EncryptedSplit, error) {
var err error var err error
encryptedRaw, err := UnArmor(encrypted) encryptedRaw, err := Unarmor(encrypted)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -112,8 +110,6 @@ func SplitArmor(encrypted string) (*models.EncryptedSplit, error) {
return outSplit, err return outSplit, err
} }
//encode length based on 4.2.2. in the RFC //encode length based on 4.2.2. in the RFC
func encodedLength(length int) (b []byte) { func encodedLength(length int) (b []byte) {
if length < 192 { if length < 192 {

View file

@ -6,10 +6,10 @@ import (
"io/ioutil" "io/ioutil"
"golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp"
armorUtils "proton/pmcrypto/armor"
"golang.org/x/crypto/openpgp/packet"
"proton/pmcrypto/internal"
"golang.org/x/crypto/openpgp/armor" "golang.org/x/crypto/openpgp/armor"
"golang.org/x/crypto/openpgp/packet"
armorUtils "proton/pmcrypto/armor"
"proton/pmcrypto/internal"
"proton/pmcrypto/models" "proton/pmcrypto/models"
) )
@ -52,7 +52,7 @@ func (pm *PmCrypto) EncryptAttachmentBinKey(plainData []byte, fileName string, p
//EncryptAttachment ... //EncryptAttachment ...
func (pm *PmCrypto) EncryptAttachment(plainData []byte, fileName string, publicKey string) (*models.EncryptedSplit, error) { func (pm *PmCrypto) EncryptAttachment(plainData []byte, fileName string, publicKey string) (*models.EncryptedSplit, error) {
rawPubKey, err := armorUtils.UnArmor(publicKey) rawPubKey, err := armorUtils.Unarmor(publicKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -89,7 +89,7 @@ func (pm *PmCrypto) DecryptAttachmentBinKey(keyPacket []byte, dataPacket []byte,
encryptedReader := io.MultiReader(keyReader, dataReader) encryptedReader := io.MultiReader(keyReader, dataReader)
config := &packet.Config{ Time: pm.getTimeGenerator() } config := &packet.Config{Time: pm.getTimeGenerator()}
md, err := openpgp.ReadMessage(encryptedReader, privKeyEntries, nil, config) md, err := openpgp.ReadMessage(encryptedReader, privKeyEntries, nil, config)
if err != nil { if err != nil {
@ -107,7 +107,7 @@ func (pm *PmCrypto) DecryptAttachmentBinKey(keyPacket []byte, dataPacket []byte,
//DecryptAttachment ... //DecryptAttachment ...
func (pm *PmCrypto) DecryptAttachment(keyPacket []byte, dataPacket []byte, privateKey string, passphrase string) ([]byte, error) { func (pm *PmCrypto) DecryptAttachment(keyPacket []byte, dataPacket []byte, privateKey string, passphrase string) ([]byte, error) {
rawPrivKey, err := armorUtils.UnArmor(privateKey) rawPrivKey, err := armorUtils.Unarmor(privateKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -123,7 +123,7 @@ func (pm *PmCrypto) EncryptAttachmentWithPassword(plainData []byte, password str
return "", err return "", err
} }
config := &packet.Config{ Time: pm.getTimeGenerator() } config := &packet.Config{Time: pm.getTimeGenerator()}
plaintext, err := openpgp.SymmetricallyEncrypt(w, []byte(password), nil, config) plaintext, err := openpgp.SymmetricallyEncrypt(w, []byte(password), nil, config)
if err != nil { if err != nil {
@ -154,7 +154,7 @@ func (pm *PmCrypto) DecryptAttachmentWithPassword(keyPacket []byte, dataPacket [
return []byte(password), nil return []byte(password), nil
} }
config := &packet.Config{ Time: pm.getTimeGenerator() } config := &packet.Config{Time: pm.getTimeGenerator()}
md, err := openpgp.ReadMessage(encryptedReader, nil, prompt, config) md, err := openpgp.ReadMessage(encryptedReader, nil, prompt, config)
if err != nil { if err != nil {

View file

@ -5,7 +5,7 @@ import (
"crypto" "crypto"
"encoding/hex" "encoding/hex"
"errors" "errors"
"strings" "strings"
"time" "time"
"golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp"
@ -21,7 +21,6 @@ const (
failed = 3 failed = 3
) )
//IsKeyExpiredBin ... //IsKeyExpiredBin ...
func (pm *PmCrypto) IsKeyExpiredBin(publicKey []byte) (bool, error) { func (pm *PmCrypto) IsKeyExpiredBin(publicKey []byte) (bool, error) {
now := pm.getNow() now := pm.getNow()
@ -77,7 +76,7 @@ func (pm *PmCrypto) IsKeyExpiredBin(publicKey []byte) (bool, error) {
//IsKeyExpired .... //IsKeyExpired ....
// will user the cached time to check // will user the cached time to check
func (pm *PmCrypto) IsKeyExpired(publicKey string) (bool, error) { func (pm *PmCrypto) IsKeyExpired(publicKey string) (bool, error) {
rawPubKey, err := armor.UnArmor(publicKey) rawPubKey, err := armor.Unarmor(publicKey)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -133,7 +132,6 @@ func (pm *PmCrypto) generateKey(userName string, domain string, passphrase strin
return "", err return "", err
} }
rawPwd := []byte(passphrase) rawPwd := []byte(passphrase)
if newEntity.PrivateKey != nil && !newEntity.PrivateKey.Encrypted { if newEntity.PrivateKey != nil && !newEntity.PrivateKey.Encrypted {
if err := newEntity.PrivateKey.Encrypt(rawPwd); err != nil { if err := newEntity.PrivateKey.Encrypt(rawPwd); err != nil {
@ -158,7 +156,7 @@ func (pm *PmCrypto) generateKey(userName string, domain string, passphrase strin
} }
func (pm *PmCrypto) GenerateRSAKeyWithPrimes(userName string, domain string, passphrase string, bits int, func (pm *PmCrypto) GenerateRSAKeyWithPrimes(userName string, domain string, passphrase string, bits int,
primeone []byte, primetwo []byte, primethree []byte, primefour []byte) (string, error) { primeone []byte, primetwo []byte, primethree []byte, primefour []byte) (string, error) {
return pm.generateKey(userName, domain, passphrase, "rsa", bits, primeone, primetwo, primethree, primefour) return pm.generateKey(userName, domain, passphrase, "rsa", bits, primeone, primetwo, primethree, primefour)
} }
@ -171,6 +169,7 @@ func (pm *PmCrypto) GenerateRSAKeyWithPrimes(userName string, domain string, pas
func (pm *PmCrypto) GenerateKey(userName string, domain string, passphrase string, keyType string, bits int) (string, error) { func (pm *PmCrypto) GenerateKey(userName string, domain string, passphrase string, keyType string, bits int) (string, error) {
return pm.generateKey(userName, domain, passphrase, keyType, bits, nil, nil, nil, nil) return pm.generateKey(userName, domain, passphrase, keyType, bits, nil, nil, nil, nil)
} }
// UpdatePrivateKeyPassphrase ... // UpdatePrivateKeyPassphrase ...
func (pm *PmCrypto) UpdatePrivateKeyPassphrase(privateKey string, oldPassphrase string, newPassphrase string) (string, error) { func (pm *PmCrypto) UpdatePrivateKeyPassphrase(privateKey string, oldPassphrase string, newPassphrase string) (string, error) {
@ -217,7 +216,7 @@ func (pm *PmCrypto) UpdatePrivateKeyPassphrase(privateKey string, oldPassphrase
} }
// CheckKey print out the key and subkey fingerprint // CheckKey print out the key and subkey fingerprint
func (pm *PmCrypto) CheckKey(pubKey string) (string, error) { func (pm *PmCrypto) CheckKey(pubKey string) (string, error) {
pubKeyReader := strings.NewReader(pubKey) pubKeyReader := strings.NewReader(pubKey)
entries, err := openpgp.ReadArmoredKeyRing(pubKeyReader) entries, err := openpgp.ReadArmoredKeyRing(pubKeyReader)
if err != nil { if err != nil {

View file

@ -10,8 +10,8 @@ import (
"golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/armor" "golang.org/x/crypto/openpgp/armor"
"golang.org/x/crypto/openpgp/packet"
errors2 "golang.org/x/crypto/openpgp/errors" errors2 "golang.org/x/crypto/openpgp/errors"
"golang.org/x/crypto/openpgp/packet"
"math" "math"
armorUtils "proton/pmcrypto/armor" armorUtils "proton/pmcrypto/armor"
"proton/pmcrypto/internal" "proton/pmcrypto/internal"
@ -23,7 +23,7 @@ import (
// privateKey : armored private use to decrypt message // privateKey : armored private use to decrypt message
// passphrase : match with private key to decrypt message // passphrase : match with private key to decrypt message
func (pm *PmCrypto) DecryptMessage(encryptedText string, privateKey string, passphrase string) (string, error) { func (pm *PmCrypto) DecryptMessage(encryptedText string, privateKey string, passphrase string) (string, error) {
privKeyRaw, err := armorUtils.UnArmor(privateKey) privKeyRaw, err := armorUtils.Unarmor(privateKey)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -41,7 +41,7 @@ func (pm *PmCrypto) DecryptMessageBinKey(encryptedText string, privateKey []byte
return "", err return "", err
} }
encryptedio, err := internal.UnArmor(encryptedText) encryptedio, err := internal.Unarmor(encryptedText)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -59,7 +59,7 @@ func (pm *PmCrypto) DecryptMessageBinKey(encryptedText string, privateKey []byte
} }
} }
config := &packet.Config{ Time: pm.getTimeGenerator() } config := &packet.Config{Time: pm.getTimeGenerator()}
md, err := openpgp.ReadMessage(encryptedio.Body, privKeyEntries, nil, config) md, err := openpgp.ReadMessage(encryptedio.Body, privKeyEntries, nil, config)
if err != nil { if err != nil {
@ -76,13 +76,13 @@ func (pm *PmCrypto) DecryptMessageBinKey(encryptedText string, privateKey []byte
return string(b), nil return string(b), nil
} }
// DecryptMessageVerifyPrivbinkeys decrypt message and verify the signature // DecryptMessageVerifyPrivBinKeys decrypt message and verify the signature
// veriferKey string: armored verifier keys // verifierKey string: armored verifier keys
// privateKey []byte: unarmored private key to decrypt. could be mutiple // privateKey []byte: unarmored private key to decrypt. could be mutiple
func (pm *PmCrypto) DecryptMessageVerifyPrivbinkeys(encryptedText string, veriferKey string, privateKeys []byte, passphrase string, verifyTime int64) (*models.DecryptSignedVerify, error) { func (pm *PmCrypto) DecryptMessageVerifyPrivBinKeys(encryptedText string, verifierKey string, privateKeys []byte, passphrase string, verifyTime int64) (*models.DecryptSignedVerify, error) {
if len(veriferKey) > 0 { if len(verifierKey) > 0 {
verifierRaw, err := armorUtils.UnArmor(veriferKey) verifierRaw, err := armorUtils.Unarmor(verifierKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -91,19 +91,19 @@ func (pm *PmCrypto) DecryptMessageVerifyPrivbinkeys(encryptedText string, verife
return pm.decryptMessageVerifyAllBin(encryptedText, nil, privateKeys, passphrase, verifyTime) return pm.decryptMessageVerifyAllBin(encryptedText, nil, privateKeys, passphrase, verifyTime)
} }
// DecryptMessageVerifyBinKeyPrivbinkeys decrypt message and verify the signature // DecryptMessageVerifyBinKeyPrivBinKeys decrypt message and verify the signature
// veriferKey []byte: unarmored verifier keys // verifierKey []byte: unarmored verifier keys
// privateKey []byte: unarmored private key to decrypt. could be mutiple // privateKey []byte: unarmored private key to decrypt. could be mutiple
func (pm *PmCrypto) DecryptMessageVerifyBinKeyPrivbinkeys(encryptedText string, veriferKey []byte, privateKeys []byte, passphrase string, verifyTime int64) (*models.DecryptSignedVerify, error) { func (pm *PmCrypto) DecryptMessageVerifyBinKeyPrivBinKeys(encryptedText string, verifierKey []byte, privateKeys []byte, passphrase string, verifyTime int64) (*models.DecryptSignedVerify, error) {
return pm.decryptMessageVerifyAllBin(encryptedText, veriferKey, privateKeys, passphrase, verifyTime) return pm.decryptMessageVerifyAllBin(encryptedText, verifierKey, privateKeys, passphrase, verifyTime)
} }
// DecryptMessageVerify decrypt message and verify the signature // DecryptMessageVerify decrypt message and verify the signature
// veriferKey string: armored verifier keys // verifierKey string: armored verifier keys
// privateKey string: private to decrypt // privateKey string: private to decrypt
func (pm *PmCrypto) DecryptMessageVerify(encryptedText string, veriferKey string, privateKey string, passphrase string, verifyTime int64) (*models.DecryptSignedVerify, error) { func (pm *PmCrypto) DecryptMessageVerify(encryptedText string, verifierKey string, privateKey string, passphrase string, verifyTime int64) (*models.DecryptSignedVerify, error) {
if len(veriferKey) > 0 { if len(verifierKey) > 0 {
verifierRaw, err := armorUtils.UnArmor(veriferKey) verifierRaw, err := armorUtils.Unarmor(verifierKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -113,20 +113,20 @@ func (pm *PmCrypto) DecryptMessageVerify(encryptedText string, veriferKey string
} }
// DecryptMessageVerifyBinKey decrypt message and verify the signature // DecryptMessageVerifyBinKey decrypt message and verify the signature
// veriferKey []byte: unarmored verifier keys // verifierKey []byte: unarmored verifier keys
// privateKey string: private to decrypt // privateKey string: private to decrypt
func (pm *PmCrypto) DecryptMessageVerifyBinKey(encryptedText string, veriferKey []byte, privateKey string, passphrase string, verifyTime int64) (*models.DecryptSignedVerify, error) { func (pm *PmCrypto) DecryptMessageVerifyBinKey(encryptedText string, verifierKey []byte, privateKey string, passphrase string, verifyTime int64) (*models.DecryptSignedVerify, error) {
privateKeyRaw, err := armorUtils.UnArmor(privateKey) privateKeyRaw, err := armorUtils.Unarmor(privateKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return pm.decryptMessageVerifyAllBin(encryptedText, veriferKey, privateKeyRaw, passphrase, verifyTime) return pm.decryptMessageVerifyAllBin(encryptedText, verifierKey, privateKeyRaw, passphrase, verifyTime)
} }
// decryptMessageVerifyAllBin // decryptMessageVerifyAllBin
// decrypt_message_verify_single_key(private_key: string, passphras: string, encrypted : string, signature : string) : decrypt_sign_verify; // decrypt_message_verify_single_key(private_key: string, passphras: string, encrypted : string, signature : string) : decrypt_sign_verify;
// decrypt_message_verify(passphras: string, encrypted : string, signature : string) : decrypt_sign_verify; // decrypt_message_verify(passphras: string, encrypted : string, signature : string) : decrypt_sign_verify;
func (pm *PmCrypto) decryptMessageVerifyAllBin(encryptedText string, veriferKey []byte, privateKey []byte, passphrase string, verifyTime int64) (*models.DecryptSignedVerify, error) { func (pm *PmCrypto) decryptMessageVerifyAllBin(encryptedText string, verifierKey []byte, privateKey []byte, passphrase string, verifyTime int64) (*models.DecryptSignedVerify, error) {
privKey := bytes.NewReader(privateKey) privKey := bytes.NewReader(privateKey)
privKeyEntries, err := openpgp.ReadKeyRing(privKey) privKeyEntries, err := openpgp.ReadKeyRing(privKey)
if err != nil { if err != nil {
@ -151,8 +151,8 @@ func (pm *PmCrypto) decryptMessageVerifyAllBin(encryptedText string, veriferKey
out.Verify = failed out.Verify = failed
var verifierEntries openpgp.EntityList var verifierEntries openpgp.EntityList
if len(veriferKey) > 0 { if len(verifierKey) > 0 {
verifierReader := bytes.NewReader(veriferKey) verifierReader := bytes.NewReader(verifierKey)
verifierEntries, err = openpgp.ReadKeyRing(verifierReader) verifierEntries, err = openpgp.ReadKeyRing(verifierReader)
if err != nil { if err != nil {
return nil, err return nil, err
@ -165,7 +165,7 @@ func (pm *PmCrypto) decryptMessageVerifyAllBin(encryptedText string, veriferKey
out.Verify = noVerifier out.Verify = noVerifier
} }
encryptedio, err := internal.UnArmor(encryptedText) encryptedio, err := internal.Unarmor(encryptedText)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -222,7 +222,7 @@ func processSignatureExpiration(md *openpgp.MessageDetails, verifyTime int64) {
if md.Signature.KeyLifetimeSecs != nil { if md.Signature.KeyLifetimeSecs != nil {
expires = int64(*md.Signature.KeyLifetimeSecs) + created expires = int64(*md.Signature.KeyLifetimeSecs) + created
} }
if created - internal.CreationTimeOffset <= verifyTime && verifyTime <= expires { if created-internal.CreationTimeOffset <= verifyTime && verifyTime <= expires {
md.SignatureError = nil md.SignatureError = nil
} }
} else { } else {
@ -238,7 +238,7 @@ func processSignatureExpiration(md *openpgp.MessageDetails, verifyTime int64) {
// privateKey : optional required when you want to sign // privateKey : optional required when you want to sign
// passphrase : optional required when you pass the private key and this passphrase must could decrypt the private key // passphrase : optional required when you pass the private key and this passphrase must could decrypt the private key
func (pm *PmCrypto) EncryptMessage(plainText string, publicKey string, privateKey string, passphrase string, trim bool) (string, error) { func (pm *PmCrypto) EncryptMessage(plainText string, publicKey string, privateKey string, passphrase string, trim bool) (string, error) {
rawPubKey, err := armorUtils.UnArmor(publicKey) rawPubKey, err := armorUtils.Unarmor(publicKey)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -290,11 +290,11 @@ func (pm *PmCrypto) EncryptMessageBinKey(plainText string, publicKey []byte, pri
} }
if signEntity == nil { if signEntity == nil {
return "", errors.New("cannot sign message, singer key is not unlocked") return "", errors.New("cannot sign message, signer key is not unlocked")
} }
} }
config := &packet.Config{DefaultCipher: packet.CipherAES256, Time: pm.getTimeGenerator() } config := &packet.Config{DefaultCipher: packet.CipherAES256, Time: pm.getTimeGenerator()}
ew, err := openpgp.Encrypt(w, pubKeyEntries, signEntity, nil, config) ew, err := openpgp.Encrypt(w, pubKeyEntries, signEntity, nil, config)
@ -315,7 +315,7 @@ func (pm *PmCrypto) EncryptMessageWithPassword(plainText string, password string
return "", err return "", err
} }
config := &packet.Config{ Time: pm.getTimeGenerator() } config := &packet.Config{Time: pm.getTimeGenerator()}
plaintext, err := openpgp.SymmetricallyEncrypt(w, []byte(password), nil, config) plaintext, err := openpgp.SymmetricallyEncrypt(w, []byte(password), nil, config)
if err != nil { if err != nil {
return "", err return "", err
@ -338,7 +338,7 @@ func (pm *PmCrypto) EncryptMessageWithPassword(plainText string, password string
//encrypted string : armored pgp message //encrypted string : armored pgp message
//output string : clear text //output string : clear text
func (pm *PmCrypto) DecryptMessageWithPassword(encrypted string, password string) (string, error) { func (pm *PmCrypto) DecryptMessageWithPassword(encrypted string, password string) (string, error) {
encryptedio, err := internal.UnArmor(encrypted) encryptedio, err := internal.Unarmor(encrypted)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -347,7 +347,7 @@ func (pm *PmCrypto) DecryptMessageWithPassword(encrypted string, password string
return []byte(password), nil return []byte(password), nil
} }
config := &packet.Config{ Time: pm.getTimeGenerator() } config := &packet.Config{Time: pm.getTimeGenerator()}
md, err := openpgp.ReadMessage(encryptedio.Body, nil, prompt, config) md, err := openpgp.ReadMessage(encryptedio.Body, nil, prompt, config)
if err != nil { if err != nil {
return "", err return "", err

View file

@ -1,10 +1,10 @@
package crypto package crypto
import ( import (
"testing"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"proton/pmcrypto/internal" "proton/pmcrypto/internal"
"testing"
) )
const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK----- const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
@ -235,7 +235,6 @@ z9GxJikRwscymWmXx2QsvhUiWeOJ05WwK+WAnKR1uVtkEJ9QJVe2chyuMORY
-----END PGP PRIVATE KEY BLOCK----- -----END PGP PRIVATE KEY BLOCK-----
` `
// define call back interface // define call back interface
type Callbacks struct { type Callbacks struct {
} }
@ -259,9 +258,9 @@ func (t Callbacks) OnError(err error) {
func TestDecrypt(t *testing.T) { func TestDecrypt(t *testing.T) {
callbacks := Callbacks{} callbacks := Callbacks{}
o := PmCrypto{} o := PmCrypto{}
block, _ := internal.UnArmor(publicKey) block, _ := internal.Unarmor(publicKey)
publicKeyUnarmored, _ := ioutil.ReadAll(block.Body) publicKeyUnarmored, _ := ioutil.ReadAll(block.Body)
block, _ = internal.UnArmor(privatekey) block, _ = internal.Unarmor(privatekey)
privateKeyUnarmored, _ := ioutil.ReadAll(block.Body) privateKeyUnarmored, _ := ioutil.ReadAll(block.Body)
o.DecryptMIMEMessage(testMessage, publicKeyUnarmored, privateKeyUnarmored, privatekeypassword, o.DecryptMIMEMessage(testMessage, publicKeyUnarmored, privateKeyUnarmored, privatekeypassword,
&callbacks, o.GetTime()) &callbacks, o.GetTime())
@ -410,4 +409,3 @@ RIzX2CG47PuGl/uvImFW/Iw=
fmt.Println(attachment) fmt.Println(attachment)
} }
} }

View file

@ -5,7 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"strings" "strings"
"golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/packet" "golang.org/x/crypto/openpgp/packet"
@ -118,7 +118,7 @@ func (pm *PmCrypto) GetSessionFromKeyPacket(keyPackage []byte, privateKey string
//KeyPacketWithPublicKey ... //KeyPacketWithPublicKey ...
func (pm *PmCrypto) KeyPacketWithPublicKey(sessionSplit *models.SessionSplit, publicKey string) ([]byte, error) { func (pm *PmCrypto) KeyPacketWithPublicKey(sessionSplit *models.SessionSplit, publicKey string) ([]byte, error) {
pubkeyRaw, err := armor.UnArmor(publicKey) pubkeyRaw, err := armor.Unarmor(publicKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -282,4 +282,4 @@ func getAlgo(cipher packet.CipherFunction) string {
} }
return algo return algo
} }

View file

@ -5,7 +5,7 @@ import (
"strings" "strings"
) )
func UnArmor(input string) (*armor.Block, error) { func Unarmor(input string) (*armor.Block, error) {
io := strings.NewReader(input) io := strings.NewReader(input)
b, err := armor.Decode(io) b, err := armor.Decode(io)
if err != nil { if err != nil {
@ -13,4 +13,4 @@ func UnArmor(input string) (*armor.Block, error) {
} }
return b, nil return b, nil
} }

View file

@ -11,7 +11,7 @@ import (
// GetFingerprint get a armored public key fingerprint // GetFingerprint get a armored public key fingerprint
func GetFingerprint(publicKey string) (string, error) { func GetFingerprint(publicKey string) (string, error) {
rawPubKey, err := armor.UnArmor(publicKey) rawPubKey, err := armor.Unarmor(publicKey)
if err != nil { if err != nil {
return "", err return "", err
} }

View file

@ -1,6 +1,5 @@
package models package models
//EncryptedSplit when encrypt attachemt //EncryptedSplit when encrypt attachemt
type EncryptedSplit struct { type EncryptedSplit struct {
DataPacket []byte DataPacket []byte
@ -8,7 +7,7 @@ type EncryptedSplit struct {
Algo string Algo string
} }
//SessionSplit splited session //SessionSplit split session
type SessionSplit struct { type SessionSplit struct {
Session []byte Session []byte
Algo string Algo string
@ -29,4 +28,3 @@ type DecryptSignedVerify struct {
//error message if verify failed //error message if verify failed
Message string Message string
} }