| Tim Windelschmidt | 6d33a43 | 2025-02-04 14:34:25 +0100 | [diff] [blame^] | 1 | // Copyright The Monogon Project Authors. |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| Lorenz Brun | 62a1edd | 2023-06-20 16:01:44 +0200 | [diff] [blame] | 4 | // 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. |
| 8 | package msguid |
| 9 | |
| 10 | import "github.com/google/uuid" |
| 11 | |
| 12 | var 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. |
| 15 | func 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. |
| 23 | func To(i [16]byte) (o uuid.UUID) { |
| 24 | for from, dest := range mixedEndianTranspose { |
| 25 | o[dest] = i[from] |
| 26 | } |
| 27 | return |
| 28 | } |