2023-08-05 04:48:29 +00:00
|
|
|
package opclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
op "github.com/1Password/connect-sdk-go/onepassword"
|
|
|
|
"golang.org/x/crypto/blake2b"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Checksum(fields []*op.ItemField) string {
|
|
|
|
newHash, err := blake2b.New256(nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
df := []string{}
|
|
|
|
for _, field := range fields {
|
|
|
|
if field.ID == "password" || field.ID == "notesPlain" || (field.Section != nil && field.Section.ID == "~annotations") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
label := field.Label
|
2023-11-26 02:35:12 +00:00
|
|
|
if field.Section != nil {
|
2023-11-26 02:36:15 +00:00
|
|
|
sectionID := field.Section.Label
|
|
|
|
if sectionID == "" {
|
|
|
|
sectionID = field.Section.ID
|
2023-11-26 02:35:12 +00:00
|
|
|
}
|
2023-11-26 02:36:15 +00:00
|
|
|
if sectionID != "" {
|
|
|
|
label = sectionID + "." + label
|
2023-11-26 02:35:12 +00:00
|
|
|
}
|
2023-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
df = append(df, label+field.Value)
|
|
|
|
}
|
|
|
|
sort.Strings(df)
|
|
|
|
newHash.Write([]byte(strings.Join(df, "")))
|
|
|
|
checksum := newHash.Sum(nil)
|
|
|
|
return fmt.Sprintf("%x", checksum)
|
|
|
|
}
|