diff --git a/rsakey/manager_local_hs256.go b/rsakey/manager_local_hs256.go index 908da4552e..9266ed7089 100644 --- a/rsakey/manager_local_hs256.go +++ b/rsakey/manager_local_hs256.go @@ -21,7 +21,8 @@ package rsakey import ( - "github.com/pborman/uuid" + "crypto/sha256" + "fmt" ) type LocalHS256Manager struct { @@ -30,9 +31,12 @@ type LocalHS256Manager struct { } func NewLocalHS256Manager(key []byte) *LocalHS256Manager { + h := sha256.New() + h.Write(key) + return &LocalHS256Manager{ key: key, - kid: uuid.New(), + kid: fmt.Sprintf("%x", h.Sum(nil)), } } diff --git a/rsakey/manager_local_hs256_test.go b/rsakey/manager_local_hs256_test.go new file mode 100644 index 0000000000..0893974e67 --- /dev/null +++ b/rsakey/manager_local_hs256_test.go @@ -0,0 +1,35 @@ +/* + * Copyright © 2017-2018 Aeneas Rekkas + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Aeneas Rekkas + * @copyright 2017-2018 Aeneas Rekkas + * @license Apache-2.0 + */ + +package rsakey + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestLocalHS256Manager(t *testing.T) { + key := []byte("somkey") + m1 := NewLocalHS256Manager(key) + m2 := NewLocalHS256Manager(key) + + assert.EqualValues(t, m1.PublicKeyID(), m2.PublicKeyID()) +}