format and comment
This commit is contained in:
parent
398de10777
commit
a92113e341
4 changed files with 12 additions and 12 deletions
|
|
@ -107,10 +107,9 @@ func (pm *PmCrypto) EncryptAttachmentLowMemory(estimatedSize int, fileName strin
|
||||||
return pm.encryptAttachment(estimatedSize, fileName, publicKey, 1<<20)
|
return pm.encryptAttachment(estimatedSize, fileName, publicKey, 1<<20)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use: ios/android only
|
|
||||||
// Helper method. Splits armored pgp session into key and packet data
|
// Helper method. Splits armored pgp session into key and packet data
|
||||||
|
// Use: ios/android only
|
||||||
func SplitArmor(encrypted string) (*models.EncryptedSplit, error) {
|
func SplitArmor(encrypted string) (*models.EncryptedSplit, error) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
encryptedRaw, err := armorUtils.Unarmor(encrypted)
|
encryptedRaw, err := armorUtils.Unarmor(encrypted)
|
||||||
|
|
@ -121,7 +120,6 @@ func SplitArmor(encrypted string) (*models.EncryptedSplit, error) {
|
||||||
encryptedReader := bytes.NewReader(encryptedRaw)
|
encryptedReader := bytes.NewReader(encryptedRaw)
|
||||||
|
|
||||||
return SeparateKeyAndData(nil, encryptedReader, len(encrypted), -1)
|
return SeparateKeyAndData(nil, encryptedReader, len(encrypted), -1)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use: ios/android only
|
// Use: ios/android only
|
||||||
|
|
|
||||||
|
|
@ -112,10 +112,9 @@ func DecryptAttKey(kr *KeyRing, keyPacket string) (key *SymmetricKey, err error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SeparateKeyAndData from packets in a pgp session
|
||||||
// Use: bridge, ios/android, go-pm-crypto, attachment.go, keyring.go
|
// Use: bridge, ios/android, go-pm-crypto, attachment.go, keyring.go
|
||||||
// Separate key and data packets in a pgp session
|
|
||||||
func SeparateKeyAndData(kr *KeyRing, r io.Reader, estimatedLength int, garbageCollector int) (outSplit *models.EncryptedSplit, err error) {
|
func SeparateKeyAndData(kr *KeyRing, r io.Reader, estimatedLength int, garbageCollector int) (outSplit *models.EncryptedSplit, err error) {
|
||||||
|
|
||||||
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
|
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
|
||||||
packets := packet.NewReader(r)
|
packets := packet.NewReader(r)
|
||||||
outSplit = &models.EncryptedSplit{}
|
outSplit = &models.EncryptedSplit{}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Unarmor from string
|
||||||
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)
|
||||||
|
|
@ -12,5 +13,4 @@ func Unarmor(input string) (*armor.Block, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return b, nil
|
return b, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,21 +5,24 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TrimNewlines removes a whitespace in the end of string (don't stop on linebreak)
|
||||||
func TrimNewlines(input string) string {
|
func TrimNewlines(input string) string {
|
||||||
var re = regexp.MustCompile(`(?m)[ \t]*$`)
|
var re = regexp.MustCompile(`(?m)[ \t]*$`)
|
||||||
return re.ReplaceAllString(input, "")
|
return re.ReplaceAllString(input, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Amount of seconds that a signature may be created after the verify time
|
// CreationTimeOffset stores amount of seconds that a signature may be created
|
||||||
// Consistent with the 2 day slack allowed in the ProtonMail Email Parser
|
// after the verify time Consistent with the 2 day slack allowed in the
|
||||||
|
// ProtonMail Email Parser
|
||||||
const CreationTimeOffset = int64(60 * 60 * 24 * 2)
|
const CreationTimeOffset = int64(60 * 60 * 24 * 2)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ARMOR_HEADER_VERSION = "Pmcrypto Golang 0.0.1 (" + constants.VERSION + ")"
|
armorHeaderVersion = "Pmcrypto Golang 0.0.1 (" + constants.VERSION + ")"
|
||||||
ARMOR_HEADER_COMMENT = "https://protonmail.com"
|
armorHeaderComment = "https://protonmail.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ArmorHeaders from golang pm-crypto
|
||||||
var ArmorHeaders = map[string]string{
|
var ArmorHeaders = map[string]string{
|
||||||
"Version": ARMOR_HEADER_VERSION,
|
"Version": armorHeaderVersion,
|
||||||
"Comment": ARMOR_HEADER_COMMENT,
|
"Comment": armorHeaderComment,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue