Standard library / crypto/subtle
crypto/subtle.ConstantTimeCopy()
Conditionally copy y to x for selector 1; retain x for 0. Slices must have equal length; any other selector is undefined. Expected stdout: 'old\nnew\n'.
Formal Syntax & Structure
go syntaxgo
func ConstantTimeCopy(v int, x, y []byte)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| v | int | Selector, exactly 0 or 1. |
| x | []byte | Destination, same length as y. |
| y | []byte | Source, same length as x. |
Working Example
Example Snippetgo
package main
import ( "crypto/subtle" "fmt")
func main() { x := []byte("old") y := []byte("new") subtle.ConstantTimeCopy(0, x, y) fmt.Println(string(x)) subtle.ConstantTimeCopy(1, x, y) fmt.Println(string(x))}