More documentation fixes

This commit is contained in:
Daniel Huigens 2019-05-15 14:57:35 +02:00
parent 388fa872e7
commit 4ef882c564
8 changed files with 26 additions and 18 deletions

View file

@ -1,4 +1,5 @@
// This package contains a set of helper methods for armoring and unarmoring // Package armor contains a set of helper methods for armoring and unarmoring
// data.
package armor package armor
import ( import (
@ -12,17 +13,18 @@ import (
"io/ioutil" "io/ioutil"
) )
// ArmorKey makes bytes input key to armor format // ArmorKey armors input as a public key.
func ArmorKey(input []byte) (string, error) { func ArmorKey(input []byte) (string, error) {
return ArmorWithType(input, constants.PublicKeyHeader) return ArmorWithType(input, constants.PublicKeyHeader)
} }
// ArmorWithTypeBuffered takes input from io.Writer and returns io.WriteCloser which can be read for armored code // ArmorWithTypeBuffered returns a io.WriteCloser which, when written to, writes
// armored data to w with the given armorType.
func ArmorWithTypeBuffered(w io.Writer, armorType string) (io.WriteCloser, error) { func ArmorWithTypeBuffered(w io.Writer, armorType string) (io.WriteCloser, error) {
return armor.Encode(w, armorType, nil) return armor.Encode(w, armorType, nil)
} }
// ArmorWithType makes bytes input to armor format // ArmorWithType armors input with the given armorType.
func ArmorWithType(input []byte, armorType string) (string, error) { func ArmorWithType(input []byte, armorType string) (string, error) {
var b bytes.Buffer var b bytes.Buffer
@ -39,7 +41,7 @@ func ArmorWithType(input []byte, armorType string) (string, error) {
return b.String(), nil return b.String(), nil
} }
// Unarmor an armored key to bytes key // Unarmor unarmors an armored 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 {
@ -48,7 +50,7 @@ func Unarmor(input string) ([]byte, error) {
return ioutil.ReadAll(b.Body) return ioutil.ReadAll(b.Body)
} }
// ReadClearSignedMessage reads clear message from a clearsign package (package containing cleartext and signature) // ReadClearSignedMessage returns the message body from a clearsigned message.
func ReadClearSignedMessage(signedMessage string) (string, error) { func ReadClearSignedMessage(signedMessage string) (string, error) {
modulusBlock, rest := clearsign.Decode([]byte(signedMessage)) modulusBlock, rest := clearsign.Decode([]byte(signedMessage))
if len(rest) != 0 { if len(rest) != 0 {

View file

@ -1,6 +1,7 @@
// Package constants provides a set of common OpenPGP constants.
package constants package constants
// Definitions for armored data // Constants for armored data.
const ( const (
ArmorHeaderVersion = "GopenPGP 0.0.1 (" + Version + ")" ArmorHeaderVersion = "GopenPGP 0.0.1 (" + Version + ")"
ArmorHeaderComment = "https://gopenpgp.org" ArmorHeaderComment = "https://gopenpgp.org"

View file

@ -1,9 +1,9 @@
package constants package constants
// Definitions for cipher suites // Cipher suite names.
const ( const (
ThreeDES = "3des" ThreeDES = "3des"
TripleDES = "tripledes" TripleDES = "tripledes" // Both "3des" and "tripledes" refer to 3DES.
CAST5 = "cast5" CAST5 = "cast5"
AES128 = "aes128" AES128 = "aes128"
AES192 = "aes192" AES192 = "aes192"

View file

@ -174,7 +174,7 @@ func (kr *KeyRing) Encrypt(w io.Writer, sign *KeyRing, filename string, canonica
func() time.Time { return GetGopenPGP().GetTime() }) func() time.Time { return GetGopenPGP().GetTime() })
} }
// EncryptCore is common encryption method for desktop and mobile clients // EncryptCore is lower-level encryption method used by KeyRing.Encrypt.
func EncryptCore(w io.Writer, encryptEntities []*openpgp.Entity, signEntity *openpgp.Entity, filename string, func EncryptCore(w io.Writer, encryptEntities []*openpgp.Entity, signEntity *openpgp.Entity, filename string,
canonicalizeText bool, timeGenerator func() time.Time) (io.WriteCloser, error) { canonicalizeText bool, timeGenerator func() time.Time) (io.WriteCloser, error) {

View file

@ -5,7 +5,7 @@ import (
"strings" "strings"
) )
// Unarmor from string // Unarmor unarmors an armored 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)

View file

@ -1,3 +1,4 @@
// Package internal contains internal methods and constants.
package internal package internal
import ( import (
@ -6,17 +7,18 @@ import (
"github.com/ProtonMail/gopenpgp/constants" "github.com/ProtonMail/gopenpgp/constants"
) )
// TrimNewlines removes a whitespace in the end of string (don't stop on linebreak) // TrimNewlines removes whitespace from the end of each line of the input
// string.
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, "")
} }
// CreationTimeOffset stores the amount of seconds that a signature may be // CreationTimeOffset stores the amount of seconds that a signature may be
// created in the future, to compensate for clock skew // created in the future, to compensate for clock skew.
const CreationTimeOffset = int64(60 * 60 * 24 * 2) const CreationTimeOffset = int64(60 * 60 * 24 * 2)
// ArmorHeaders from gopenpgp // ArmorHeaders is a map of default armor headers.
var ArmorHeaders = map[string]string{ var ArmorHeaders = map[string]string{
"Version": constants.ArmorHeaderVersion, "Version": constants.ArmorHeaderVersion,
"Comment": constants.ArmorHeaderComment, "Comment": constants.ArmorHeaderComment,

View file

@ -1,20 +1,21 @@
// Provides high-level public data models used for communication mainly with mobile clients // Package models provides structs containing message data.
package models package models
// EncryptedSplit when encrypt attachment // EncryptedSplit contains a separate session key packet and symmetrically
// encrypted data packet.
type EncryptedSplit struct { type EncryptedSplit struct {
DataPacket []byte DataPacket []byte
KeyPacket []byte KeyPacket []byte
Algo string Algo string
} }
// EncryptedSigned encrypt_sign_package // EncryptedSigned contains an encrypted message and signature.
type EncryptedSigned struct { type EncryptedSigned struct {
Encrypted string Encrypted string
Signature string Signature string
} }
// DecryptSignedVerify decrypt_sign_verify // DecryptSignedVerify contains a decrypted message and verification result.
type DecryptSignedVerify struct { type DecryptSignedVerify struct {
//clear text //clear text
Plaintext string Plaintext string

View file

@ -1,3 +1,5 @@
// Package subtle contains subtly insecure methods not recommended for casual
// use.
package subtle package subtle
import ( import (