Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expiration parameter #56

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openpgp/clearsign/clearsign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestMultiSign(t *testing.T) {

desc := fmt.Sprintf("%d keys; %d of which will be used to verify", nKeys+nExtra, nKeys)
for i := 0; i < nKeys+nExtra; i++ {
e, err := openpgp.NewEntity("name", "comment", "email", &config)
e, err := openpgp.NewEntity("name", "comment", "email", nil, &config)
if err != nil {
t.Errorf("cannot create key: %v", err)
continue nextTest
Expand Down
2 changes: 1 addition & 1 deletion openpgp/integration_tests/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func generateFreshTestVectors() (vectors []testVector, err error) {
}

// Generate keys
newEntity, errKG := openpgp.NewEntity(name, comment, email, config)
newEntity, errKG := openpgp.NewEntity(name, comment, email, nil, config)
if errKG != nil {
panic(errKG)
}
Expand Down
3 changes: 2 additions & 1 deletion openpgp/key_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// single identity composed of the given full name, comment and email, any of
// which may be empty but must not contain any of "()<>\x00".
// If config is nil, sensible defaults will be used.
func NewEntity(name, comment, email string, config *packet.Config) (*Entity, error) {
func NewEntity(name, comment, email string, expiration *uint32, config *packet.Config) (*Entity, error) {
creationTime := config.Now()

uid := packet.NewUserId(name, comment, email)
Expand Down Expand Up @@ -96,6 +96,7 @@ func NewEntity(name, comment, email string, config *packet.Config) (*Entity, err
FlagEncryptStorage: true,
FlagEncryptCommunications: true,
IssuerKeyId: &primary.PublicKey.KeyId,
KeyLifetimeSecs: expiration,
},
}

Expand Down
38 changes: 19 additions & 19 deletions openpgp/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func TestNewEntityWithDefaultHash(t *testing.T) {
c := &packet.Config{
DefaultHash: hash,
}
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", c)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, c)
if err != nil {
t.Fatal(err)
}
Expand All @@ -495,7 +495,7 @@ func TestNewEntityWithDefaultHash(t *testing.T) {
}

func TestNewEntityNilConfigPreferredHash(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -509,7 +509,7 @@ func TestNewEntityNilConfigPreferredHash(t *testing.T) {
}

func TestNewEntityCorrectName(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -531,7 +531,7 @@ func TestNewEntityWithDefaultCipher(t *testing.T) {
c := &packet.Config{
DefaultCipher: cipher,
}
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", c)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, c)
if err != nil {
t.Fatal(err)
}
Expand All @@ -549,7 +549,7 @@ func TestNewEntityWithDefaultCipher(t *testing.T) {
}

func TestNewEntityNilConfigPreferredSymmetric(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -569,7 +569,7 @@ func TestNewEntityWithDefaultAead(t *testing.T) {
DefaultMode: aeadMode,
},
}
entity, err := NewEntity("Botvinnik", "1.e4", "tal@chess.com", cfg)
entity, err := NewEntity("Botvinnik", "1.e4", "tal@chess.com", nil, cfg)
if err != nil {
t.Fatal(err)
}
Expand All @@ -589,7 +589,7 @@ func TestNewEntityWithDefaultAead(t *testing.T) {
}

func TestNewEntityPublicSerialization(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -606,7 +606,7 @@ func TestNewEntityPublicSerialization(t *testing.T) {
}

func TestNewEntityPrivateSerialization(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -643,7 +643,7 @@ func TestEntityPrivateSerialization(t *testing.T) {
}

func TestAddSubkey(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -679,7 +679,7 @@ func TestAddSubkey(t *testing.T) {
}

func TestAddSubkeySerialized(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -719,7 +719,7 @@ func TestAddSubkeyWithConfig(t *testing.T) {
DefaultHash: crypto.SHA512,
Algorithm: packet.PubKeyAlgoEdDSA,
}
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -784,7 +784,7 @@ func TestAddSubkeyWithConfigSerialized(t *testing.T) {
DefaultHash: crypto.SHA512,
Algorithm: packet.PubKeyAlgoEdDSA,
}
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -845,7 +845,7 @@ func TestAddSubkeyWithConfigSerialized(t *testing.T) {
}

func TestRevokeKey(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -872,7 +872,7 @@ func TestRevokeKeyWithConfig(t *testing.T) {
DefaultHash: crypto.SHA512,
}

entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -900,7 +900,7 @@ func TestRevokeKeyWithConfig(t *testing.T) {
}

func TestRevokeSubkey(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -941,14 +941,14 @@ func TestRevokeSubkey(t *testing.T) {
}

func TestRevokeSubkeyWithAnotherEntity(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}

sk := entity.Subkeys[0]

newEntity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
newEntity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -960,7 +960,7 @@ func TestRevokeSubkeyWithAnotherEntity(t *testing.T) {
}

func TestRevokeSubkeyWithInvalidSignature(t *testing.T) {
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -979,7 +979,7 @@ func TestRevokeSubkeyWithConfig(t *testing.T) {
DefaultHash: crypto.SHA512,
}

entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil)
entity, err := NewEntity("Golang Gopher", "Test Key", "no-reply@golang.com", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions openpgp/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestSignDetachedP256(t *testing.T) {
func TestNewEntity(t *testing.T) {

// Check bit-length with no config.
e, err := NewEntity("Test User", "test", "test@example.com", nil)
e, err := NewEntity("Test User", "test", "test@example.com", nil, nil)
if err != nil {
t.Errorf("failed to create entity: %s", err)
return
Expand All @@ -90,7 +90,7 @@ func TestNewEntity(t *testing.T) {

// Check bit-length with a config.
cfg := &packet.Config{RSABits: 1024}
e, err = NewEntity("Test User", "test", "test@example.com", cfg)
e, err = NewEntity("Test User", "test", "test@example.com", nil, cfg)
if err != nil {
t.Errorf("failed to create entity: %s", err)
return
Expand Down