======================== CODE SNIPPETS ======================== TITLE: Go hash/maphash Package Functions DESCRIPTION: Documents functions for hashing comparable types using a seed. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_9 LANGUAGE: APIDOC CODE: ``` pkg hash/maphash: Functions: Comparable[$0 comparable](Seed, $0) uint64 Computes a hash for a comparable type using a seed. Parameters: - seed: The hash seed. - value: The comparable value to hash. Returns: - uint64: The computed hash value. WriteComparable[*Hash, $0 comparable](*Hash, $0) Writes a comparable type to a hash state. Parameters: - h: The hash state. - value: The comparable value to write. ``` ---------------------------------------- TITLE: Go Crypto Package Constants DESCRIPTION: Defines constants for BLAKE2 hash algorithms within the crypto package. SOURCE: https://github.com/golang/go/blob/master/api/go1.9.txt#_snippet_0 LANGUAGE: go CODE: ``` package crypto const BLAKE2b_256 = 17 const BLAKE2b_384 = 18 const BLAKE2b_512 = 19 const BLAKE2s_256 = 16 ``` ---------------------------------------- TITLE: Go crypto/x509 Package Types and Methods DESCRIPTION: Documents types and methods for X.509 certificate handling, including OID manipulation and certificate verification options. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_5 LANGUAGE: APIDOC CODE: ``` pkg crypto/x509: Constants: NoValidChains InvalidReason = 10 Indicates that no valid certificate chains could be found. Types: OID []uint8 Represents an Object Identifier. PolicyMapping struct Defines a mapping between certificate policies. Fields: - IssuerDomainPolicy: The issuer's domain policy OID. - SubjectDomainPolicy: The subject's domain policy OID. Certificate struct Represents an X.509 certificate. Fields: - InhibitAnyPolicy: An integer indicating inhibition of any policy. - InhibitAnyPolicyZero: A boolean indicating zero inhibition of any policy. - InhibitPolicyMapping: An integer indicating inhibition of policy mapping. - InhibitPolicyMappingZero: A boolean indicating zero inhibition of policy mapping. - PolicyMappings: A slice of PolicyMapping structs. - RequireExplicitPolicy: An integer indicating requirement of explicit policy. - RequireExplicitPolicyZero: A boolean indicating zero requirement of explicit policy. VerifyOptions struct Options for verifying a certificate chain. Fields: - CertificatePolicies: A slice of OID representing allowed certificate policies. Methods: (OID) AppendBinary([]uint8) ([]uint8, error) Appends the OID's binary representation to a byte slice. Parameters: - buf: The buffer to append to. Returns: - []uint8: The updated buffer. - error: An error if appending fails. (OID) AppendText([]uint8) ([]uint8, error) Appends the OID's text representation to a byte slice. Parameters: - buf: The buffer to append to. Returns: - []uint8: The updated buffer. - error: An error if appending fails. ``` ---------------------------------------- TITLE: Go crypto/x509 OID Methods DESCRIPTION: Documentation for methods associated with the OID type in the crypto/x509 package. These methods are used for manipulating and appending data to Object Identifiers (OIDs). SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_29 LANGUAGE: APIDOC CODE: ``` pkg crypto/x509, method (OID) AppendBinary([]uint8) ([]uint8, error) // AppendBinary appends binary data to an OID, returning the new OID bytes. // Parameters: // data: The binary data to append. // Returns: // The updated OID byte slice and an error if the operation fails. method (OID) AppendText([]uint8) ([]uint8, error) // AppendText appends text data to an OID, returning the new OID bytes. // Parameters: // data: The text data to append. // Returns: // The updated OID byte slice and an error if the operation fails. ``` ---------------------------------------- TITLE: Go crypto/subtle Package Function DESCRIPTION: Documents the WithDataIndependentTiming function from the crypto/subtle package, used for constant-time operations. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_3 LANGUAGE: APIDOC CODE: ``` pkg crypto/subtle: Functions: WithDataIndependentTiming(f func()) Executes the given function f with data-independent timing. This is useful for cryptographic operations to prevent timing side-channels. Parameters: - f: The function to execute. ``` ---------------------------------------- TITLE: Go crypto/x509 Certificate and Policy Structures DESCRIPTION: Documentation for types and constants in the crypto/x509 package related to certificate validation and policy handling. It covers certificate fields, policy mappings, and verification options. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_28 LANGUAGE: APIDOC CODE: ``` pkg crypto/x509, const NoValidChains = 10 // NoValidChains is an InvalidReason constant indicating no valid certificate chains were found. pkg crypto/x509, const NoValidChains InvalidReason // InvalidReason is a type alias for the NoValidChains constant. pkg crypto/x509, type Certificate struct, InhibitAnyPolicy int // Certificate represents an X.509 certificate. // InhibitAnyPolicy specifies the number of policy constraints. // InhibitAnyPolicyZero: A boolean indicating if InhibitAnyPolicy is zero. // InhibitPolicyMapping: Specifies the number of policy mapping constraints. // InhibitPolicyMappingZero: A boolean indicating if InhibitPolicyMapping is zero. // PolicyMappings: A slice of PolicyMapping structures. // RequireExplicitPolicy: Specifies the number of explicit policy requirements. // RequireExplicitPolicyZero: A boolean indicating if RequireExplicitPolicy is zero. pkg crypto/x509, type PolicyMapping struct // PolicyMapping represents a mapping between certificate policies. // Fields: // IssuerDomainPolicy: The OID of the issuer's domain policy. // SubjectDomainPolicy: The OID of the subject's domain policy. pkg crypto/x509, type VerifyOptions struct, CertificatePolicies []OID // VerifyOptions contains options for verifying a certificate chain. // CertificatePolicies: A slice of OIDs representing the certificate policies to check. ``` ---------------------------------------- TITLE: Crypto Package Interfaces and Functions DESCRIPTION: Documentation for the crypto package, including the MessageSigner interface and the SignMessage function. It outlines the methods available for signing messages and the required parameters. SOURCE: https://github.com/golang/go/blob/master/api/go1.25.txt#_snippet_0 LANGUAGE: APIDOC CODE: ``` pkg crypto: func SignMessage(Signer, io.Reader, []uint8, SignerOpts) ([]uint8, error) Signs a message using the provided signer and options. Parameters: Signer: The cryptographic signer. io.Reader: The reader for the message content. []uint8: The data to sign. SignerOpts: Options for the signing process. Returns: []uint8: The signature. error: An error if the signing process fails. type MessageSigner interface Defines the interface for signing messages. Methods: Public() PublicKey Returns the public key associated with the signer. Sign(io.Reader, []uint8, SignerOpts) ([]uint8, error) Signs data from a reader. SignMessage(io.Reader, []uint8, SignerOpts) ([]uint8, error) Signs a message from a reader. ``` ---------------------------------------- TITLE: Go math/big Package Methods DESCRIPTION: Documents methods for appending text representations of big.Float numbers. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_11 LANGUAGE: APIDOC CODE: ``` pkg math/big: Methods: (*Float) AppendText([]uint8) ([]uint8, error) Appends the text representation of the big.Float to a buffer. Parameters: - buf: The buffer to append to. Returns: - []uint8: The updated buffer. - error: An error if appending fails. ``` ---------------------------------------- TITLE: Go crypto/sha3 Package Documentation DESCRIPTION: Details types and methods within the crypto/sha3 package, including the SHAKE and SHA3 types and their associated methods like UnmarshalBinary and Write. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_2 LANGUAGE: APIDOC CODE: ``` pkg crypto/sha3: Types: SHA3 struct Represents the SHA3 hashing algorithm. SHAKE struct Represents the SHAKE extendable-output function. Methods: (*SHAKE) UnmarshalBinary([]uint8) error Unmarshals the SHAKE state from a byte slice. Parameters: - data: The byte slice containing the marshaled state. Returns: - error: An error if the unmarshalling fails. (*SHAKE) Write([]uint8) (int, error) Writes data to the SHAKE state. Parameters: - p: The byte slice to write. Returns: - n: The number of bytes written. - error: An error if the write operation fails. ``` ---------------------------------------- TITLE: Go crypto/sha3 SHAKE Methods DESCRIPTION: Documentation for the SHAKE type within the crypto/sha3 package. It includes methods for unmarshalling binary data and writing byte slices, essential for cryptographic operations. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_25 LANGUAGE: APIDOC CODE: ``` pkg crypto/sha3, type SHAKE struct // SHAKE is a type for SHA-3 Extendable-Output Functions. method (*SHAKE) UnmarshalBinary([]uint8) error // UnmarshalBinary populates the SHAKE state from a binary encoding. // Parameters: // data: The binary data to unmarshal. // Returns: // An error if the data is invalid or unmarshalling fails. method (*SHAKE) Write([]uint8) (int, error) // Write appends data to the SHAKE state. // Parameters: // data: The byte slice to write. // Returns: // The number of bytes written and an error if the write operation fails. ``` ---------------------------------------- TITLE: Go crypto/subtle WithDataIndependentTiming DESCRIPTION: Details the WithDataIndependentTiming function from the crypto/subtle package. This function is used to execute a given function with timing that is independent of the input data, enhancing security against timing attacks. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_26 LANGUAGE: APIDOC CODE: ``` pkg crypto/subtle, func WithDataIndependentTiming(func()) // WithDataIndependentTiming executes the provided function f with data-independent timing. // This is crucial for cryptographic operations to prevent side-channel attacks. // Parameters: // f: The function to execute with timing protection. ``` ---------------------------------------- TITLE: Crypto Package Constants and Types DESCRIPTION: Defines constants for SHA hash sizes and interfaces for cryptographic operations like decryption. SOURCE: https://github.com/golang/go/blob/master/api/go1.5.txt#_snippet_3 LANGUAGE: go CODE: ``` pkg crypto, const SHA512_224 = 14 ``` LANGUAGE: go CODE: ``` pkg crypto, const SHA512_224 Hash ``` LANGUAGE: go CODE: ``` pkg crypto, const SHA512_256 = 15 ``` LANGUAGE: go CODE: ``` pkg crypto, const SHA512_256 Hash ``` LANGUAGE: go CODE: ``` pkg crypto, type Decrypter interface { Decrypt, Public } ``` LANGUAGE: go CODE: ``` pkg crypto, type Decrypter interface, Decrypt(io.Reader, []uint8, DecrypterOpts) ([]uint8, error) ``` LANGUAGE: go CODE: ``` pkg crypto, type Decrypter interface, Public() PublicKey ``` LANGUAGE: go CODE: ``` pkg crypto, type DecrypterOpts interface {} ``` ---------------------------------------- TITLE: Weak Reference Pointer DESCRIPTION: Implements a generic weak reference mechanism using pointers. Allows creating pointers that do not prevent the referenced object from being garbage collected. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_44 LANGUAGE: go CODE: ``` package weak // Pointer is a generic type representing a weak reference to a value. type Pointer[$0 interface{}] struct { // Make creates a new weak reference pointer. Make func(*$0) Pointer[$0] // Value returns the value pointed to, or nil if the object has been garbage collected. Value func() *$0 } // Make creates a new weak reference pointer to the given value. func Make[$0 interface{}](v *$0) Pointer[$0] ``` ---------------------------------------- TITLE: String Splitting and Iteration DESCRIPTION: Functions for splitting strings based on various criteria and generating sequences of substrings. These functions return iterators for efficient processing of string segments. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_42 LANGUAGE: go CODE: ``` package strings import "iter" // FieldsFuncSeq splits the string s at each run of Unicode code points c satisfying f(c) and returns an iterator of slices of s. func FieldsFuncSeq(s string, f func(int32) bool) iter.Seq[string] // FieldsSeq splits the string s at each run of Unicode code points and returns an iterator of slices of s. func FieldsSeq(s string) iter.Seq[string] // Lines splits the string s into an iterator of strings, one per line. func Lines(s string) iter.Seq[string] // SplitAfterSeq splits the string s into an iterator of substrings after each instance of sep. func SplitAfterSeq(s string, sep string) iter.Seq[string] // SplitSeq splits the string s into an iterator of substrings separated by sep. func SplitSeq(s string, sep string) iter.Seq[string] ``` ---------------------------------------- TITLE: Runtime Cleanup and GOROOT DESCRIPTION: Utilities for managing runtime cleanup tasks and accessing Go's runtime environment variables. Includes a generic cleanup mechanism and information about the Go installation directory. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_41 LANGUAGE: go CODE: ``` package runtime import "time" // Cleanup represents a deferred cleanup action. type Cleanup struct { // Stop stops the cleanup action. Stop func() } // AddCleanup registers a cleanup function to be called when the context is done or the program exits. // It takes a pointer to a context-like object, a cleanup function, and its argument. func AddCleanup[$0 interface{}, $1 interface{}](ctx *$0, cleanupFunc func($1), arg $1) Cleanup // GOROOT is the path to the Go installation directory. (Deprecated) // var GOROOT string ``` ---------------------------------------- TITLE: Go hash/maphash Hashing Functions DESCRIPTION: Details the hashing functions provided by the hash/maphash package. These functions are designed for efficient, non-cryptographic hashing, suitable for hash tables and other data structures. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_35 LANGUAGE: APIDOC CODE: ``` pkg hash/maphash, func Comparable[$0 comparable](Seed, $0) uint64 // Comparable computes a hash for a comparable value using a given seed. // Parameters: // Seed: The seed for the hash function. // value: The comparable value to hash. // Returns: // The computed hash value as a uint64. func WriteComparable[$0 comparable](*Hash, $0) // WriteComparable appends a comparable value to the hash state. // Parameters: // h: The Hash object to write to. // value: The comparable value to hash and append. ``` ---------------------------------------- TITLE: Go crypto/tls Package Constants and Types DESCRIPTION: Details constants and struct types related to TLS configuration and X25519 key exchange within the crypto/tls package. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_4 LANGUAGE: APIDOC CODE: ``` pkg crypto/tls: Constants: X25519MLKEM768 = 4588 CurveID Represents the CurveID for X25519 ML-KEM 768. Types: ClientHelloInfo struct Contains information about a TLS client hello. Fields: - Extensions: A slice of uint16 representing TLS extensions. Config struct Contains configuration for TLS clients and servers. Fields: - EncryptedClientHelloKeys: A slice of EncryptedClientHelloKey for ECH. EncryptedClientHelloKey struct Represents a key for Encrypted Client Hello (ECH). Fields: - Config: Configuration data as a byte slice. - PrivateKey: The private key as a byte slice. - SendAsRetry: A boolean indicating if this key is sent as a retry. ``` ---------------------------------------- TITLE: Go Crypto Package Constants (BLAKE2s) DESCRIPTION: Defines constants for BLAKE2s hash algorithms within the crypto package. SOURCE: https://github.com/golang/go/blob/master/api/go1.9.txt#_snippet_29 LANGUAGE: go CODE: ``` package crypto const BLAKE2s_256 = 16 ``` ---------------------------------------- TITLE: Go Crypto Package Constants (BLAKE2) DESCRIPTION: Defines constants for BLAKE2 hash algorithms within the crypto package. SOURCE: https://github.com/golang/go/blob/master/api/go1.9.txt#_snippet_23 LANGUAGE: go CODE: ``` package crypto const BLAKE2b_256 = 17 const BLAKE2b_384 = 18 const BLAKE2b_512 = 19 const BLAKE2s_256 = 16 ``` ---------------------------------------- TITLE: Go Crypto Package Constants (Hash Types) DESCRIPTION: Defines constants for BLAKE2 hash algorithms and their corresponding hash types within the crypto package. SOURCE: https://github.com/golang/go/blob/master/api/go1.9.txt#_snippet_15 LANGUAGE: go CODE: ``` package crypto // Hash is a placeholder type for hash functions. type Hash int const BLAKE2b_256 Hash = 17 const BLAKE2b_384 Hash = 18 const BLAKE2b_512 Hash = 19 const BLAKE2s_256 Hash = 16 ``` ---------------------------------------- TITLE: Go crypto/x509 CertPool Methods DESCRIPTION: Documentation for methods associated with the CertPool type in Go's crypto/x509 package. CertPool is used for managing collections of certificates, often for validation purposes. SOURCE: https://github.com/golang/go/blob/master/api/go1.19.txt#_snippet_0 LANGUAGE: APIDOC CODE: ``` pkg crypto/x509, method (*CertPool) Clone() *CertPool - Creates a copy of the CertPool. - Returns: A new CertPool containing the same certificates as the original. ``` LANGUAGE: APIDOC CODE: ``` pkg crypto/x509, method (*CertPool) Equal(*CertPool) bool - Compares two CertPools for equality. - Parameters: - other: The CertPool to compare against. - Returns: True if the pools contain the same certificates, false otherwise. ``` ---------------------------------------- TITLE: Go crypto Package Method DESCRIPTION: Documents the String method for the Hash interface in the crypto package. This method is used to return a string representation of the hash algorithm. SOURCE: https://github.com/golang/go/blob/master/api/go1.15.txt#_snippet_1 LANGUAGE: Go CODE: ``` package crypto type Hash interface { // ... other methods String() string } ``` ---------------------------------------- TITLE: crypto: SHA3 constants and Signer interface DESCRIPTION: Adds SHA3 hashing constants (SHA3_224, SHA3_256, SHA3_384, SHA3_512) to the crypto package's Hash enum. It also defines the Signer interface for cryptographic signing operations and related methods. SOURCE: https://github.com/golang/go/blob/master/api/go1.4.txt#_snippet_3 LANGUAGE: APIDOC CODE: ``` pkg crypto, const SHA3_224 = 10 pkg crypto, const SHA3_224 Hash pkg crypto, const SHA3_256 = 11 pkg crypto, const SHA3_256 Hash pkg crypto, const SHA3_384 = 12 pkg crypto, const SHA3_384 Hash pkg crypto, const SHA3_512 = 13 pkg crypto, const SHA3_512 Hash pkg crypto, method (Hash) HashFunc() Hash pkg crypto, type Signer interface { Public, Sign } pkg crypto, type Signer interface, Public() PublicKey pkg crypto, type Signer interface, Sign(io.Reader, []uint8, SignerOpts) ([]uint8, error) pkg crypto, type SignerOpts interface { HashFunc } pkg crypto, type SignerOpts interface, HashFunc() Hash ``` ---------------------------------------- TITLE: Go crypto/rsa Package Deprecated Types DESCRIPTION: Documentation for deprecated types and fields within the 'crypto/rsa' package, related to RSA key generation. SOURCE: https://github.com/golang/go/blob/master/api/go1.21.txt#_snippet_4 LANGUAGE: APIDOC CODE: ``` pkg crypto/rsa, func GenerateMultiPrimeKey //deprecated - Deprecated: Use crypto/rsa.GenerateKey or crypto/rsa.GenerateMultiPrimeKey. pkg crypto/rsa, type PrecomputedValues struct, CRTValues //deprecated - Deprecated: Use crypto/rsa.Precomputed.CRTValues. ``` ---------------------------------------- TITLE: Go crypto/tls Constants and Types DESCRIPTION: Documentation for constants and types within the crypto/tls package. This includes cryptographic curve identifiers and structures related to TLS client hello information and encrypted client hello keys. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_27 LANGUAGE: APIDOC CODE: ``` pkg crypto/tls, const X25519MLKEM768 = 4588 // X25519MLKEM768 is a constant representing a specific TLS curve ID. pkg crypto/tls, const X25519MLKEM768 CurveID // CurveID is a type alias for the X25519MLKEM768 constant. pkg crypto/tls, type ClientHelloInfo struct, Extensions []uint16 // ClientHelloInfo contains information about a TLS client hello. // Extensions is a slice of TLS extension types. pkg crypto/tls, type Config struct, EncryptedClientHelloKeys []EncryptedClientHelloKey // Config holds TLS configuration settings. // EncryptedClientHelloKeys specifies keys for encrypted client hello. pkg crypto/tls, type EncryptedClientHelloKey struct // EncryptedClientHelloKey represents a key for the Encrypted Client Hello extension. // Fields: // Config: Configuration data for the key. // PrivateKey: The private key material. // SendAsRetry: A boolean indicating if this key is sent as a retry. ``` ---------------------------------------- TITLE: Go log/slog Package Methods and Variables DESCRIPTION: Documents methods for appending text to log levels and the DiscardHandler. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_10 LANGUAGE: APIDOC CODE: ``` pkg log/slog: Variables: DiscardHandler Handler A Handler that discards all log records. Methods: (*LevelVar) AppendText([]uint8) ([]uint8, error) Appends the text representation of the level variable to a buffer. Parameters: - buf: The buffer to append to. Returns: - []uint8: The updated buffer. - error: An error if appending fails. (Level) AppendText([]uint8) ([]uint8, error) Appends the text representation of the level to a buffer. Parameters: - buf: The buffer to append to. Returns: - []uint8: The updated buffer. - error: An error if appending fails. ``` ---------------------------------------- TITLE: Crypto/RSA Private Key Decryption DESCRIPTION: Method for decrypting data using an RSA private key with specified options. SOURCE: https://github.com/golang/go/blob/master/api/go1.5.txt#_snippet_6 LANGUAGE: go CODE: ``` pkg crypto/rsa, method (*PrivateKey) Decrypt(io.Reader, []uint8, crypto.DecrypterOpts) ([]uint8, error) ``` ---------------------------------------- TITLE: Go encoding Package Interfaces DESCRIPTION: Defines interfaces for binary and text appending, used for encoding data. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_7 LANGUAGE: APIDOC CODE: ``` pkg encoding: Interfaces: BinaryAppender interface Defines a method for appending binary data. Methods: AppendBinary([]uint8) ([]uint8, error) Appends binary data to the implementer. Parameters: - data: The byte slice to append. Returns: - []uint8: The updated buffer. - error: An error if appending fails. TextAppender interface Defines a method for appending text data. Methods: AppendText([]uint8) ([]uint8, error) Appends text data to the implementer. Parameters: - data: The byte slice to append. Returns: - []uint8: The updated buffer. - error: An error if appending fails. ``` ---------------------------------------- TITLE: Go SHA3 Hashing API Documentation DESCRIPTION: Comprehensive documentation for Go's SHA3 hashing algorithms, including SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128, SHAKE256, and CSHAKE variants. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_1 LANGUAGE: APIDOC CODE: ``` pkg crypto/sha3 SHA3 Hashing Functions: func New224() *SHA3 Returns a new SHA3-224 hash.Hash. func New256() *SHA3 Returns a new SHA3-256 hash.Hash. func New384() *SHA3 Returns a new SHA3-384 hash.Hash. func New512() *SHA3 Returns a new SHA3-512 hash.Hash. func Sum224(data []uint8) [28]uint8 Sum224 returns the SHA3-224 checksum of the data. func Sum256(data []uint8) [32]uint8 Sum256 returns the SHA3-256 checksum of the data. func Sum384(data []uint8) [48]uint8 Sum384 returns the SHA3-384 checksum of the data. func Sum512(data []uint8) [64]uint8 Sum512 returns the SHA3-512 checksum of the data. SHAKE Hashing Functions: func NewSHAKE128() *SHAKE Returns a new SHAKE128 extendable-output function. func NewSHAKE256() *SHAKE Returns a new SHAKE256 extendable-output function. func NewCSHAKE128(prefix []uint8, suffix []uint8) *SHAKE Returns a new CSHAKE128 extendable-output function with custom prefix and suffix. Parameters: prefix: The custom prefix for CSHAKE. suffix: The custom suffix for CSHAKE. func NewCSHAKE256(prefix []uint8, suffix []uint8) *SHAKE Returns a new CSHAKE256 extendable-output function with custom prefix and suffix. Parameters: prefix: The custom prefix for CSHAKE. suffix: The custom suffix for CSHAKE. func SumSHAKE128(data []uint8, outputLen int) []uint8 SumSHAKE128 returns the SHAKE128 digest of the data with the specified output length. Parameters: data: The input data. outputLen: The desired length of the output digest. func SumSHAKE256(data []uint8, outputLen int) []uint8 SumSHAKE256 returns the SHAKE256 digest of the data with the specified output length. Parameters: data: The input data. outputLen: The desired length of the output digest. Methods on SHA3: func (h *SHA3) AppendBinary(data []uint8) ([]uint8, error) Appends data to the hash and returns the updated hash state. func (h *SHA3) BlockSize() int Returns the block size of the hash in bytes. func (h *SHA3) MarshalBinary() ([]uint8, error) Marshals the hash state into a byte slice. func (h *SHA3) Reset() Resets the hash state. func (h *SHA3) Size() int Returns the size of the hash output in bytes. func (h *SHA3) Sum(data []uint8) []uint8 Adds data to the hash and returns the current hash sum. func (h *SHA3) UnmarshalBinary(data []uint8) error Unmarshals the hash state from a byte slice. func (h *SHA3) Write(data []uint8) (int, error) Writes data to the hash. Methods on SHAKE: func (h *SHAKE) AppendBinary(data []uint8) ([]uint8, error) Appends data to the SHAKE function and returns the updated state. func (h *SHAKE) BlockSize() int Returns the block size of the SHAKE function in bytes. func (h *SHAKE) MarshalBinary() ([]uint8, error) Marshals the SHAKE state into a byte slice. func (h *SHAKE) Read(data []uint8) (int, error) Reads data from the SHAKE function's output stream. func (h *SHAKE) Reset() Resets the SHAKE state. ``` ---------------------------------------- TITLE: Crypto/Cipher AEAD Function DESCRIPTION: Function to create a new AEAD cipher using GCM with a specified nonce size. SOURCE: https://github.com/golang/go/blob/master/api/go1.5.txt#_snippet_4 LANGUAGE: go CODE: ``` pkg crypto/cipher, func NewGCMWithNonceSize(Block, int) (AEAD, error) ``` ---------------------------------------- TITLE: Go Crypto X509 Unwrap Method DESCRIPTION: Documentation for the Unwrap method of SystemRootsError in the crypto/x509 package. This method is used to unwrap the underlying error. SOURCE: https://github.com/golang/go/blob/master/api/go1.16.txt#_snippet_1 LANGUAGE: APIDOC CODE: ``` crypto/x509 Package Methods: (SystemRootsError) Unwrap() error - Returns the underlying error that caused SystemRootsError. - Parameters: None. - Returns: - error: The wrapped error. ``` ---------------------------------------- TITLE: Go net/url URL AppendBinary Method DESCRIPTION: Demonstrates the AppendBinary method for the net/url.URL type, which likely serializes URL components into a byte slice. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_19 LANGUAGE: go CODE: ``` package net/url // AppendBinary appends the binary representation of the URL to the given byte slice. // Parameters: // []uint8: The byte slice to append to. // Returns: // []uint8: The updated byte slice. // error: An error if the conversion fails. func (u *URL) AppendBinary([]uint8) ([]uint8, error) ``` ---------------------------------------- TITLE: Go Crypto/X509 Deprecated API DESCRIPTION: This section details deprecated functions and types within the crypto/x509 and crypto/x509/pkix packages related to Certificate Revocation Lists (CRLs). Users are advised to migrate to newer APIs. SOURCE: https://github.com/golang/go/blob/master/api/go1.19.txt#_snippet_23 LANGUAGE: APIDOC CODE: ``` pkg crypto/x509: // Deprecated: Use crypto/x509.ParseCRL instead. func ParseCRL(b []byte) (*pkix.CertificateList, error) ParseCRL parses a DER-encoded CRL. // Deprecated: Use crypto/x509.ParseDERCRL instead. func ParseDERCRL(b []byte) (*pkix.CertificateList, error) ParseDERCRL parses a DER-encoded CRL. func (c *Certificate) CheckCRLSignature() error CheckCRLSignature reports whether the signature of c is valid against the issuer of c. func (c *Certificate) CreateCRL(rand io.Reader, priv interface{}, revoked []pkix.RevokedCertificate, opts pkix.CreateCRLOptions) (io.Reader, error) CreateCRL creates a Certificate Revocation List (CRL). pkg crypto/x509/pkix: // Deprecated: Use pkix.CertificateList instead. type CertificateList pkix.CertificateList // Deprecated: Use pkix.TBSCertificateList instead. type TBSCertificateList pkix.TBSCertificateList ``` ---------------------------------------- TITLE: Go testing.B Loop Method DESCRIPTION: Describes the Loop method of the testing.B type, which is used in benchmarks to control the execution loop and determine if the benchmark should continue. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_24 LANGUAGE: go CODE: ``` package testing // B is the type parameter for benchmarking. // Methods: // Loop() bool: Returns true if the benchmark should continue running. ``` ---------------------------------------- TITLE: Go Crypto/X509 Package Functions and Types DESCRIPTION: Provides functions for retrieving the system's root certificate pool and defines error types related to certificate operations. SOURCE: https://github.com/golang/go/blob/master/api/go1.7.txt#_snippet_4 LANGUAGE: APIDOC CODE: ``` pkg crypto/x509: func SystemCertPool() (*CertPool, error) - SystemCertPool returns the system's root certificate pool. - Returns: - A pointer to the CertPool containing system roots and an error if retrieval fails. type SystemRootsError struct { Err error - Err holds the underlying error encountered during system root retrieval. } - SystemRootsError is returned when there is an error retrieving the system's root certificate pool. ``` ---------------------------------------- TITLE: Go math/big Float AppendText Method DESCRIPTION: Details the AppendText method for the math/big.Float type. This method is used to append the string representation of a big.Float to a byte slice. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_37 LANGUAGE: APIDOC CODE: ``` pkg math/big, method (*Float) AppendText([]uint8) ([]uint8, error) // AppendText appends the string representation of the Float to a byte slice. // Parameters: // b: The byte slice to append to. // Returns: // The updated byte slice and an error if the operation fails. ``` ---------------------------------------- TITLE: Crypto/SHA512 Constants and Functions DESCRIPTION: Provides constants for SHA-512 digest sizes and functions for creating and summing hashes. SOURCE: https://github.com/golang/go/blob/master/api/go1.5.txt#_snippet_8 LANGUAGE: go CODE: ``` pkg crypto/sha512, const Size224 = 28 ``` LANGUAGE: go CODE: ``` pkg crypto/sha512, const Size224 ideal-int ``` LANGUAGE: go CODE: ``` pkg crypto/sha512, const Size256 = 32 ``` LANGUAGE: go CODE: ``` pkg crypto/sha512, const Size256 ideal-int ``` LANGUAGE: go CODE: ``` pkg crypto/sha512, func New512_224() hash.Hash ``` LANGUAGE: go CODE: ``` pkg crypto/sha512, func New512_256() hash.Hash ``` LANGUAGE: go CODE: ``` pkg crypto/sha512, func Sum512_224([]uint8) [28]uint8 ``` LANGUAGE: go CODE: ``` pkg crypto/sha512, func Sum512_256([]uint8) [32]uint8 ``` ---------------------------------------- TITLE: Go ML-KEM API Documentation DESCRIPTION: Documentation for the Go ML-KEM (Module Learning With Errors Key Encapsulation) package, covering key generation, encapsulation, decapsulation, and key management operations. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_0 LANGUAGE: APIDOC CODE: ``` pkg crypto/mlkem Constants: CiphertextSize1024 = 1568 CiphertextSize768 = 1088 EncapsulationKeySize1024 = 1568 EncapsulationKeySize768 = 1184 SeedSize = 64 SharedKeySize = 32 Key Generation: func GenerateKey1024() (*DecapsulationKey1024, error) Generates a new ML-KEM key pair for the 1024-bit security level. Returns a DecapsulationKey1024 and an error if generation fails. func GenerateKey768() (*DecapsulationKey768, error) Generates a new ML-KEM key pair for the 768-bit security level. Returns a DecapsulationKey768 and an error if generation fails. Key Creation from Bytes: func NewDecapsulationKey1024(keyBytes []uint8) (*DecapsulationKey1024, error) Creates a DecapsulationKey1024 from a byte slice. Parameters: keyBytes: The byte representation of the decapsulation key. Returns a DecapsulationKey1024 and an error if the bytes are invalid. func NewDecapsulationKey768(keyBytes []uint8) (*DecapsulationKey768, error) Creates a DecapsulationKey768 from a byte slice. Parameters: keyBytes: The byte representation of the decapsulation key. Returns a DecapsulationKey768 and an error if the bytes are invalid. func NewEncapsulationKey1024(keyBytes []uint8) (*EncapsulationKey1024, error) Creates an EncapsulationKey1024 from a byte slice. Parameters: keyBytes: The byte representation of the encapsulation key. Returns an EncapsulationKey1024 and an error if the bytes are invalid. func NewEncapsulationKey768(keyBytes []uint8) (*EncapsulationKey768, error) Creates an EncapsulationKey768 from a byte slice. Parameters: keyBytes: The byte representation of the encapsulation key. Returns an EncapsulationKey768 and an error if the bytes are invalid. Methods on DecapsulationKey1024: func (dk *DecapsulationKey1024) Bytes() []uint8 Returns the byte representation of the decapsulation key. func (dk *DecapsulationKey1024) Decapsulate(ciphertext []uint8) ([]uint8, error) Decapsulates a ciphertext to recover the shared secret. Parameters: ciphertext: The ciphertext to decapsulate. Returns the shared secret and an error if decapsulation fails. func (dk *DecapsulationKey1024) EncapsulationKey() *EncapsulationKey1024 Returns the corresponding public encapsulation key. Methods on DecapsulationKey768: func (dk *DecapsulationKey768) Bytes() []uint8 Returns the byte representation of the decapsulation key. func (dk *DecapsulationKey768) Decapsulate(ciphertext []uint8) ([]uint8, error) Decapsulates a ciphertext to recover the shared secret. Parameters: ciphertext: The ciphertext to decapsulate. Returns the shared secret and an error if decapsulation fails. func (dk *DecapsulationKey768) EncapsulationKey() *EncapsulationKey768 Returns the corresponding public encapsulation key. Methods on EncapsulationKey1024: func (ek *EncapsulationKey1024) Bytes() []uint8 Returns the byte representation of the encapsulation key. func (ek *EncapsulationKey1024) Encapsulate() ([]uint8, []uint8) Encapsulates a shared secret, producing a ciphertext and the shared secret. Returns the ciphertext and the shared secret. Methods on EncapsulationKey768: func (ek *EncapsulationKey768) Bytes() []uint8 Returns the byte representation of the encapsulation key. func (ek *EncapsulationKey768) Encapsulate() ([]uint8, []uint8) Encapsulates a shared secret, producing a ciphertext and the shared secret. Returns the ciphertext and the shared secret. ``` ---------------------------------------- TITLE: HTTP/2 Configuration and Protocols DESCRIPTION: Defines configurations and protocols for HTTP/2 in Go's net/http package. Includes settings for connection management, stream limits, and protocol features. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_39 LANGUAGE: APIDOC CODE: ``` package net/http // HTTP2Config holds HTTP/2 configuration settings. type HTTP2Config struct { // CountError is a function to count errors encountered during HTTP/2 processing. CountError func(string) // MaxConcurrentStreams is the maximum number of concurrent streams that can be initiated by the peer. MaxConcurrentStreams int // MaxDecoderHeaderTableSize is the maximum size of the header compression table for decoding. MaxDecoderHeaderTableSize int // MaxEncoderHeaderTableSize is the maximum size of the header compression table for encoding. MaxEncoderHeaderTableSize int // MaxReadFrameSize is the maximum size of an HTTP/2 frame that the server will read. MaxReadFrameSize int // MaxReceiveBufferPerConnection is the maximum buffer size for receiving data per connection. MaxReceiveBufferPerConnection int // MaxReceiveBufferPerStream is the maximum buffer size for receiving data per stream. MaxReceiveBufferPerStream int // PermitProhibitedCipherSuites indicates whether to permit prohibited cipher suites. PermitProhibitedCipherSuites bool // PingTimeout is the duration to wait for a ping acknowledgment. PingTimeout time.Duration // SendPingTimeout is the duration to wait before sending a ping. SendPingTimeout time.Duration // WriteByteTimeout is the duration to wait before timing out a write operation. WriteByteTimeout time.Duration } // Server and Transport can use HTTP2 configuration. // type Server struct { HTTP2 *HTTP2Config } // type Transport struct { HTTP2 *HTTP2Config } // Protocols manages HTTP protocol settings. type Protocols struct { // SetHTTP1 enables or disables HTTP/1.1 support. SetHTTP1 func(bool) // SetHTTP2 enables or disables HTTP/2 support. SetHTTP2 func(bool) // SetUnencryptedHTTP2 enables or disables unencrypted HTTP/2 support. SetUnencryptedHTTP2 func(bool) // HTTP1 returns whether HTTP/1.1 is enabled. HTTP1 func() bool // HTTP2 returns whether HTTP/2 is enabled. HTTP2 func() bool // String returns a string representation of the protocols. String func() string // UnencryptedHTTP2 returns whether unencrypted HTTP/2 is enabled. UnencryptedHTTP2 func() bool } // Server and Transport can use Protocols configuration. // type Server struct { Protocols *Protocols } // type Transport struct { Protocols *Protocols } ``` ---------------------------------------- TITLE: File System Operations (os package) DESCRIPTION: Provides functions and methods for interacting with the file system, including opening files, creating directories, and managing file information. It introduces the `Root` type for root directory operations. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_snippet_40 LANGUAGE: go CODE: ``` package os import ( "io/fs" "time" ) // OpenInRoot opens a file or directory in the specified root path. func OpenInRoot(rootPath string, name string) (*File, error) // OpenRoot opens a root directory for file system operations. func OpenRoot(name string) (*Root, error) // Root represents a root directory for file system operations. type Root struct { // Close closes the root directory. Close func() error // Create creates a new file in the root directory. Create func(name string) (*File, error) // FS returns the file system interface. FS func() fs.FS // Lstat returns the FileInfo for a file or directory, without following symlinks. Lstat func(name string) (fs.FileInfo, error) // Mkdir creates a directory in the root directory. Mkdir func(name string, perm fs.FileMode) error // Name returns the name of the root directory. Name func() string // Open opens a file in the root directory. Open func(name string) (*File, error) // OpenFile opens a file in the root directory with specified flags and mode. OpenFile func(name string, flag int, perm fs.FileMode) (*File, error) // OpenRoot opens a subdirectory as a new root. OpenRoot func(name string) (*Root, error) // Remove removes a file or directory from the root. Remove func(name string) error // Stat returns the FileInfo for a file or directory, following symlinks. Stat func(name string) (fs.FileInfo, error) } // File represents an open file. type File struct {} // FileInfo represents file metadata. type FileInfo interface {} ``` ======================== QUESTIONS AND ANSWERS ======================== TOPIC: Go Package Declarations Q: What are the SHA512 hash sizes defined in Go's crypto package? A: The crypto package defines SHA512_224 as a hash with a value of 14 and SHA512_256 as a hash with a value of 15. SOURCE: https://github.com/golang/go/blob/master/api/go1.5.txt#_qa_5 ---------------------------------------- TOPIC: Go Crypto and Bytes Package Documentation Q: What functionality does the crypto/rand package offer in Go? A: The crypto/rand package in Go provides a function, Text(), which generates a random string. This is useful for creating unique identifiers or secure random data. SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_qa_10 ---------------------------------------- TOPIC: Go Crypto and Bytes Package Documentation Q: What methods are available for the SHAKE type in Go's crypto/sha3 package? A: The SHAKE type in Go's crypto/sha3 package provides methods for extendable-output functions. These include AppendBinary(), BlockSize(), MarshalBinary(), Read(), and Reset(). SOURCE: https://github.com/golang/go/blob/master/api/go1.24.txt#_qa_14 ---------------------------------------- TOPIC: Q: What is the purpose of the golang.org/x/crypto package? A: The golang.org/x/crypto package provides cryptographic primitives and algorithms for Go programs. It includes implementations for various ciphers like ChaCha20 and ChaCha20-Poly1305, as well as utilities for handling cryptographic data structures. SOURCE: https://github.com/golang/go/blob/master/src/vendor/modules.txt#_qa_0 ---------------------------------------- TOPIC: Go Standard Library Package Documentation Q: What are the available BLAKE2 hash constants in the Go crypto package? A: The Go crypto package provides constants for BLAKE2 hashes, including BLAKE2b_256, BLAKE2b_384, BLAKE2b_512, and BLAKE2s_256. SOURCE: https://github.com/golang/go/blob/master/api/go1.9.txt#_qa_0 ---------------------------------------- TOPIC: Go Package Updates and API Additions Q: What new SHA3 hash constants have been added to the `crypto` package's `Hash` enum in Go? A: The Go `crypto` package's `Hash` enum now includes constants for SHA3 variants: `SHA3_224`, `SHA3_256`, `SHA3_384`, and `SHA3_512`. SOURCE: https://github.com/golang/go/blob/master/api/go1.4.txt#_qa_3 ---------------------------------------- TOPIC: Go Package Documentation Q: What functionality does the `crypto/ecdsa` package provide for private keys? A: The `crypto/ecdsa` package allows parsing raw private keys from byte slices using `ParseRawPrivateKey`. It also provides a `Bytes()` method on the `PrivateKey` type to retrieve its byte representation. SOURCE: https://github.com/golang/go/blob/master/api/go1.25.txt#_qa_1 ---------------------------------------- TOPIC: Go Package Documentation Q: What is the purpose of the `MessageSigner` interface in the Go crypto package? A: The `MessageSigner` interface in Go's crypto package defines methods for signing messages. It includes methods like `Public()` to get the public key, `Sign()` for signing data, and `SignMessage()` for a specific message signing operation. SOURCE: https://github.com/golang/go/blob/master/api/go1.25.txt#_qa_0 ---------------------------------------- TOPIC: Go Standard Library Documentation Q: What does the `crypto/tls.QUICConn.HandleData` method do? A: The `crypto/tls.QUICConn.HandleData` method processes incoming QUIC data for a given encryption level. It takes the encryption level and the data as a byte slice, and returns an error if data handling fails. SOURCE: https://github.com/golang/go/blob/master/api/go1.21.txt#_qa_13 ---------------------------------------- TOPIC: Go Package Updates and API Additions Q: What cryptographic signing capabilities are introduced with the `Signer` interface in Go's `crypto` package? A: The `crypto` package introduces a `Signer` interface that defines methods for obtaining the public key (`Public()`) and for signing data (`Sign(...)`). It also includes a `SignerOpts` interface to specify hashing algorithms. SOURCE: https://github.com/golang/go/blob/master/api/go1.4.txt#_qa_4