blob: b5f4b6a8cb30f7e81902318f8a64866adcf77d37 [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
2// SPDX-License-Identifier: Apache-2.0
3
Lorenz Brun62a1edd2023-06-20 16:01:44 +02004// Package msguid provides functions to convert UUIDs/GUIDs to and from
5// Microsoft's idiosyncratic "mixed-endian" format.
6// See https://uefi.org/specs/UEFI/2.10/Apx_A_GUID_and_Time_Formats.html#text-representation-relationships-apxa-guid-and-time-formats
7// for an explanation of the format.
8package msguid
9
10import "github.com/google/uuid"
11
12var mixedEndianTranspose = []int{3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15}
13
14// From converts from a standard UUID into its mixed-endian encoding.
15func From(u uuid.UUID) (o [16]byte) {
16 for dest, from := range mixedEndianTranspose {
17 o[dest] = u[from]
18 }
19 return
20}
21
22// To converts a mixed-endian-encoded UUID to its standard format.
23func To(i [16]byte) (o uuid.UUID) {
24 for from, dest := range mixedEndianTranspose {
25 o[dest] = i[from]
26 }
27 return
28}