Documentation
¶
Index ¶
- func ComputeHash(data []byte) []byte
- func ComputeKeyIdentifier(keyMaterial []byte, version key.KeyCredentialVersion) string
- func ConvertFromBinaryIdentifier(keyIdentifier []byte, version key.KeyCredentialVersion) string
- func ConvertToBinaryIdentifier(keyIdentifier string, version key.KeyCredentialVersion) ([]byte, error)
- func ConvertToBinaryTime(date time.Time, source key.KeySource, version key.KeyCredentialVersion) []byte
- type DateTime
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeHash ¶
ComputeHash calculates the SHA-256 hash of the provided data.
Parameters: - data: A byte slice containing the input data to be hashed.
Returns: - A byte slice containing the SHA-256 hash of the input data.
Note: This function uses the SHA-256 hashing algorithm from the crypto/sha256 package to generate a fixed-size 32-byte hash. The resulting hash can be used for various purposes, such as data integrity verification and cryptographic operations.
func ComputeKeyIdentifier ¶
func ComputeKeyIdentifier(keyMaterial []byte, version key.KeyCredentialVersion) string
ComputeKeyIdentifier generates a key identifier based on the provided key material and version.
Parameters: - keyMaterial: A byte slice containing the key material to be used for generating the key identifier. - version: A key.KeyCredentialVersion value representing the version of the key credential.
Returns: - A string representing the generated key identifier.
Note: This function first computes the SHA-256 hash of the provided key material using the ComputeHash function. It then converts the resulting binary hash to a string representation based on the specified version using the ConvertFromBinaryIdentifier function. The generated key identifier can be used for various purposes, such as uniquely identifying cryptographic keys and credentials.
func ConvertFromBinaryIdentifier ¶
func ConvertFromBinaryIdentifier(keyIdentifier []byte, version key.KeyCredentialVersion) string
ConvertFromBinaryIdentifier converts a binary key identifier to its string representation.
Parameters: - keyIdentifier: A byte slice containing the binary representation of the key identifier. - version: A KeyCredentialVersion object representing the version of the key credential.
Returns: - A string representing the key identifier.
Note: The function handles different versions of key credentials as follows: - For version 0 and 1, the key identifier is encoded to a hexadecimal string using hex.EncodeToString. - For version 2, the key identifier is encoded to a base64 string using base64.StdEncoding.EncodeToString. - For any other version, the key identifier is treated as base64 format and is encoded using base64.StdEncoding.EncodeToString.
func ConvertToBinaryIdentifier ¶
func ConvertToBinaryIdentifier(keyIdentifier string, version key.KeyCredentialVersion) ([]byte, error)
ConvertToBinaryIdentifier converts a key identifier string to its binary representation.
Parameters:
- keyIdentifier: A string representing the key identifier to be converted.
- version: A KeyCredentialVersion object representing the version of the key credential.
Returns:
- A byte slice containing the binary representation of the key identifier.
- An error if the conversion fails.
Note:
The function handles different versions of key credentials as follows:
- For version 0 and 1, the key identifier is expected to be in hexadecimal format and is decoded using hex.DecodeString.
- For version 2, the key identifier is expected to be in base64 format and is decoded using base64.StdEncoding.DecodeString with padding.
- For any other version, the key identifier is treated as base64 format and is decoded using base64.StdEncoding.DecodeString with padding.
func ConvertToBinaryTime ¶
func ConvertToBinaryTime(date time.Time, source key.KeySource, version key.KeyCredentialVersion) []byte
ConvertToBinaryTime converts a time.Time object to its binary representation in little-endian format.
Parameters: - date: A time.Time object representing the time to be converted. - source: The source of the key, which can affect the interpretation of the time. - version: The version of the KeyCredential, which can affect the interpretation of the time.
Returns: - A byte slice containing the binary representation of the time in little-endian format.
Note: The function currently treats all versions and sources the same way, converting the time directly to a Unix time in nanoseconds and then encoding it in little-endian format.
Types ¶
type DateTime ¶
DateTime represents a point in time with additional precision.
Fields: - Time: A time.Time object representing the point in time. - Ticks: A uint64 value representing the number of 100-nanosecond intervals that have elapsed since 1601-01-01 00:00:00 UTC.
Methods: - NewDateTime: Initializes a new DateTime instance based on the provided ticks or the current time if ticks is 0. - ToUniversalTime: Converts the DateTime instance to a time.Time object in UTC.
Note: The Ticks field provides additional precision for representing time, which is useful for certain applications that require high-resolution timestamps. The Time field is a standard time.Time object that can be used with Go's time package functions.
func ConvertFromBinaryTime ¶
func ConvertFromBinaryTime(rawBinaryTime []byte, source key.KeySource, version key.KeyCredentialVersion) DateTime
ConvertFromBinaryTime converts a binary representation of time to a time.Time object. The binary representation is expected to be in little-endian format.
Parameters: - rawBinaryTime: A byte slice containing the binary representation of the time. - source: The source of the key, which can affect the interpretation of the time. - version: The version of the KeyCredential, which can affect the interpretation of the time.
Returns: - A time.Time object representing the converted time.
Note: The function currently treats all versions and sources the same way, converting the binary timestamp directly to a Unix time in nanoseconds.
Src : https://github.com/microsoft/referencesource/blob/master/mscorlib/system/datetime.cs
func NewDateTime ¶
NewDateTime initializes a new DateTime instance.
Parameters:
- ticks: A uint64 value representing the number of 100-nanosecond intervals that have elapsed since 1601-01-01 00:00:00 UTC. If ticks is 0, the function sets the current time and calculates ticks from 1601 to now.
Returns: - A DateTime object initialized with the provided ticks or the current time if ticks is 0.
Note: The function calculates the number of nanoseconds between 1601-01-01 and the UNIX epoch (1970-01-01) to convert ticks to a time.Time object. If ticks is 0, the function sets the current time and calculates the ticks from 1601 to the current time. Otherwise, it sets the time based on the provided ticks.
func (DateTime) String ¶
String returns the string representation of the DateTime instance.
Returns: - A string representing the DateTime instance in the default format used by the time.Time type.
Note: This function leverages the String method of the embedded time.Time type to provide a human-readable representation of the DateTime instance. The format typically includes the date, time, and time zone.
func (DateTime) ToBytes ¶
ToBytes converts the DateTime instance to its binary representation in little-endian format.
Returns: - A byte slice containing the binary representation of the DateTime instance in little-endian format.
Note: This function encodes the Ticks field of the DateTime instance as a 64-bit unsigned integer in little-endian format.
func (DateTime) ToTicks ¶
ToTicks returns the number of 100-nanosecond intervals (ticks) that have elapsed since 1601-01-01 00:00:00 UTC.
Returns: - A uint64 value representing the number of 100-nanosecond intervals (ticks) since 1601-01-01 00:00:00 UTC.
Note: This function provides a way to retrieve the internal tick count of the DateTime instance, which is useful for binary time representations and calculations.
func (DateTime) ToUniversalTime ¶
ToUniversalTime converts the DateTime instance to a time.Time object in UTC.
Returns: - A time.Time object representing the DateTime instance in Coordinated Universal Time (UTC).
Note: This function ensures that the time is represented in the UTC time zone, regardless of the original time zone of the DateTime instance.