File: util.go

package info (click to toggle)
golang-github-spiffe-go-spiffe 2.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,116 kB
  • sloc: makefile: 157
file content (34 lines) | stat: -rw-r--r-- 732 bytes parent folder | download | duplicates (2)
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
28
29
30
31
32
33
34
package jwtutil

import (
	"crypto"

	"github.com/spiffe/go-spiffe/v2/internal/cryptoutil"
)

// CopyJWTAuthorities copies JWT authorities from a map to a new map.
func CopyJWTAuthorities(jwtAuthorities map[string]crypto.PublicKey) map[string]crypto.PublicKey {
	copiedJWTAuthorities := make(map[string]crypto.PublicKey)
	for key, jwtAuthority := range jwtAuthorities {
		copiedJWTAuthorities[key] = jwtAuthority
	}
	return copiedJWTAuthorities
}

func JWTAuthoritiesEqual(a, b map[string]crypto.PublicKey) bool {
	if len(a) != len(b) {
		return false
	}

	for k, pka := range a {
		pkb, ok := b[k]
		if !ok {
			return false
		}
		if equal, _ := cryptoutil.PublicKeyEqual(pka, pkb); !equal {
			return false
		}
	}

	return true
}