aboutsummaryrefslogtreecommitdiff
path: root/account.go
blob: 526463609be0ea5fa196790db869cdd950eae7d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package acme

import (
	"crypto/rand"
	"crypto/rsa"
	"net/mail"
)

type Account struct {
	Contact []string
	PrivKey *rsa.PrivateKey
}

func NewAccount(email string, bits int) (Account, error) {
	m, err := mail.ParseAddress(email)
	if err != nil {
		return Account{}, err
	}
	key, err := rsa.GenerateKey(rand.Reader, bits)
	if err != nil {
		return Account{}, err
	}
	return Account{
		Contact: []string{"mailto:" + m.Address},
		PrivKey: key,
	}, nil
}