github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/crypto/ed25519/ed25519_test.go (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ed25519
     6  
     7  import (
     8  	"github.com/shogo82148/std/log"
     9  )
    10  
    11  func Example_ed25519ctx() {
    12  	pub, priv, err := GenerateKey(nil)
    13  	if err != nil {
    14  		log.Fatal(err)
    15  	}
    16  
    17  	msg := []byte("The quick brown fox jumps over the lazy dog")
    18  
    19  	sig, err := priv.Sign(nil, msg, &Options{
    20  		Context: "Example_ed25519ctx",
    21  	})
    22  	if err != nil {
    23  		log.Fatal(err)
    24  	}
    25  
    26  	if err := VerifyWithOptions(pub, msg, sig, &Options{
    27  		Context: "Example_ed25519ctx",
    28  	}); err != nil {
    29  		log.Fatal("invalid signature")
    30  	}
    31  }