示例#1
0
// This is an entry point that largely defines "normal" miniLock behaviour.
// If sendToSender is true, then the sender's ID is added to recipients.
func EncryptFileContentsWithStrings(filename string, fileContents []byte, senderEmail, senderPassphrase string, sendToSender bool, recipientIDs ...string) (miniLockContents []byte, err error) {
	var (
		senderKey, this_recipient *taber.Keys
		recipientKeyList          []*taber.Keys
		this_id                   string
	)
	senderKey, err = taber.FromEmailAndPassphrase(senderEmail, senderPassphrase)
	if err != nil {
		return nil, err
	}
	if sendToSender {
		this_id, err = senderKey.EncodeID()
		if err != nil {
			return nil, err
		}
		recipientIDs = append(recipientIDs, this_id)
	}
	recipientKeyList = make([]*taber.Keys, 0, len(recipientIDs))
	// TODO: Randomise iteration here?
	for _, this_id = range recipientIDs {
		this_recipient, err = taber.FromID(this_id)
		if err != nil {
			return nil, err
		}
		recipientKeyList = append(recipientKeyList, this_recipient)
	}
	miniLockContents, err = EncryptFileContents(filename, fileContents, senderKey, recipientKeyList...)
	if err != nil {
		return nil, err
	}
	return miniLockContents, nil
}
示例#2
0
// Import a miniLock ID as a public key.
func ImportID(id string) (*taber.Keys, error) {
	return taber.FromID(id)
}
示例#3
0
// SenderPubkey returns the pubkey of the sender who (allegedly) created this DecryptInfoEntry.
func (die *DecryptInfoEntry) SenderPubkey() (*taber.Keys, error) {
	return taber.FromID(die.SenderID)
}