aboutsummaryrefslogtreecommitdiff
path: root/account.go
blob: 62d321399df8a4a1565fef526ee51cc798c0431f (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        `json:"contact"`
	PrivKey *rsa.PrivateKey `json:"key"`
}

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
}