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

NameTypeDescription
vintSelector, exactly 0 or 1.
x[]byteDestination, same length as y.
y[]byteSource, 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))}
Go Reference