MCPcopy
hub / github.com/getsops/sops / sortKeyGroupIndices

Function sortKeyGroupIndices

sops.go:899–926  ·  view source on GitHub ↗

sortKeyGroupIndices returns indices that would sort the KeyGroup according to decryptionOrder

(group KeyGroup, decryptionOrder []string)

Source from the content-addressed store, hash-verified

897// sortKeyGroupIndices returns indices that would sort the KeyGroup
898// according to decryptionOrder
899func sortKeyGroupIndices(group KeyGroup, decryptionOrder []string) []int {
900 priorities := make(map[string]int)
901 // give ordered weights
902 for i, v := range decryptionOrder {
903 priorities[v] = i
904 }
905 maxPriority := len(decryptionOrder)
906 // initialize indices
907 n := len(group)
908 indices := make([]int, n)
909 for i := 0; i < n; i++ {
910 indices[i] = i
911 }
912 sort.SliceStable(indices, func(i, j int) bool {
913 keyTypeI := group[indices[i]].TypeToIdentifier()
914 keyTypeJ := group[indices[j]].TypeToIdentifier()
915 priorityI, ok := priorities[keyTypeI]
916 if !ok {
917 priorityI = maxPriority
918 }
919 priorityJ, ok := priorities[keyTypeJ]
920 if !ok {
921 priorityJ = maxPriority
922 }
923 return priorityI < priorityJ
924 })
925 return indices
926}
927
928// decryptKey tries to decrypt the contents of the provided MasterKey with any
929// of the key services, returning as soon as one key service succeeds.

Callers 2

TestSortKeyGroupIndicesFunction · 0.85
decryptKeyGroupFunction · 0.85

Calls 1

TypeToIdentifierMethod · 0.65

Tested by 1

TestSortKeyGroupIndicesFunction · 0.68