specclone

package
v1.0.201 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package specclone provides deep cloning functionality for uTLS ClientHelloSpec structures.

This package is essential for creating independent copies of TLS client specifications without sharing memory references, preventing unintended mutations between cloned instances.

The package handles complete cloning of utls.ClientHelloSpec structures, including:

  • Basic fields (TLS versions, cipher suites, compression methods)
  • Complex nested extension structures (20+ supported extension types)
  • Dynamic extension types through reflection-based cloning
  • Safe handling of nil pointers and empty collections

Example usage:

spec, err := utls.UTLSIdToSpec(utls.HelloFirefox_120)
if err != nil {
	panic(err)
}

// Clone the spec
cloned := specclone.SpecClone(&spec)

// Modifications to original don't affect clone
spec.TLSVersMin = 0x0301  // Change original
// cloned.TLSVersMin remains unchanged

The cloning process ensures:

  • No shared memory references between original and clone
  • Safe handling of nil pointers at all levels
  • Proper deep copying of nested data structures
  • Thread-safe operations (no shared mutable state)

Performance considerations:

  • Uses reflection for unknown extension types (performance overhead)
  • Creates complete copies of all data structures
  • Memory usage scales with complexity of input specification

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

Clone creates a deep copy of a utls.ClientHelloSpec.

This function performs complete deep cloning of all fields and nested structures, ensuring the returned clone is completely independent from the original.

Parameters:

  • c: Pointer to the source ClientHelloSpec to clone

Returns:

  • Pointer to a new ClientHelloSpec with all fields deeply copied
  • Returns nil if input is nil

The function handles:

  • Basic fields: TLSVersMin, TLSVersMax, GetSessionID
  • Slices: CipherSuites, CompressionMethods (with independent memory)
  • Extensions: All supported extension types with proper deep copying

Supported extension types include:

  • SNIExtension, ALPNExtension, StatusRequestExtension
  • SupportedCurvesExtension, SignatureAlgorithmsExtension
  • KeyShareExtension, SessionTicketExtension, PreSharedKeyExtension
  • And 15+ more extension types

For unknown extension types, the function falls back to reflection-based deep cloning to ensure completeness.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL