-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: add internal/note, internal/sumweb, internal/tlog from golang…
….org/x/exp/sumdb Copied and updated import paths. Eventually we will probably publish these packages somewhere in golang.org/x (as non-internal packages) and then we will be able to vendor them properly. For now, copy. sumweb.globsMatchPath moved to str.GlobsMatchPath. Change-Id: I4585e6dc5daa423e4ca9669195d41e58e7c8c275 Reviewed-on: https://go-review.googlesource.com/c/go/+/173950 Reviewed-by: Jay Conrod <jayconrod@google.com>
- Loading branch information
Showing
17 changed files
with
4,654 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copyright 2019 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package note_test | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"cmd/go/internal/note" | ||
) | ||
|
||
func ExampleSign() { | ||
skey := "PRIVATE+KEY+PeterNeumann+c74f20a3+AYEKFALVFGyNhPJEMzD1QIDr+Y7hfZx09iUvxdXHKDFz" | ||
text := "If you think cryptography is the answer to your problem,\n" + | ||
"then you don't know what your problem is.\n" | ||
|
||
signer, err := note.NewSigner(skey) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
msg, err := note.Sign(¬e.Note{Text: text}, signer) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
os.Stdout.Write(msg) | ||
|
||
// Output: | ||
// If you think cryptography is the answer to your problem, | ||
// then you don't know what your problem is. | ||
// | ||
// — PeterNeumann x08go/ZJkuBS9UG/SffcvIAQxVBtiFupLLr8pAcElZInNIuGUgYN1FFYC2pZSNXgKvqfqdngotpRZb6KE6RyyBwJnAM= | ||
} | ||
|
||
func ExampleOpen() { | ||
vkey := "PeterNeumann+c74f20a3+ARpc2QcUPDhMQegwxbzhKqiBfsVkmqq/LDE4izWy10TW" | ||
msg := []byte("If you think cryptography is the answer to your problem,\n" + | ||
"then you don't know what your problem is.\n" + | ||
"\n" + | ||
"— PeterNeumann x08go/ZJkuBS9UG/SffcvIAQxVBtiFupLLr8pAcElZInNIuGUgYN1FFYC2pZSNXgKvqfqdngotpRZb6KE6RyyBwJnAM=\n") | ||
|
||
verifier, err := note.NewVerifier(vkey) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
verifiers := note.VerifierList(verifier) | ||
|
||
n, err := note.Open(msg, verifiers) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Printf("%s (%08x):\n%s", n.Sigs[0].Name, n.Sigs[0].Hash, n.Text) | ||
|
||
// Output: | ||
// PeterNeumann (c74f20a3): | ||
// If you think cryptography is the answer to your problem, | ||
// then you don't know what your problem is. | ||
} | ||
|
||
var rand = struct { | ||
Reader io.Reader | ||
}{ | ||
zeroReader{}, | ||
} | ||
|
||
type zeroReader struct{} | ||
|
||
func (zeroReader) Read(buf []byte) (int, error) { | ||
for i := range buf { | ||
buf[i] = 0 | ||
} | ||
return len(buf), nil | ||
} | ||
|
||
func ExampleSign_add_signatures() { | ||
vkey := "PeterNeumann+c74f20a3+ARpc2QcUPDhMQegwxbzhKqiBfsVkmqq/LDE4izWy10TW" | ||
msg := []byte("If you think cryptography is the answer to your problem,\n" + | ||
"then you don't know what your problem is.\n" + | ||
"\n" + | ||
"— PeterNeumann x08go/ZJkuBS9UG/SffcvIAQxVBtiFupLLr8pAcElZInNIuGUgYN1FFYC2pZSNXgKvqfqdngotpRZb6KE6RyyBwJnAM=\n") | ||
|
||
verifier, err := note.NewVerifier(vkey) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
verifiers := note.VerifierList(verifier) | ||
|
||
n, err := note.Open([]byte(msg), verifiers) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
skey, vkey, err := note.GenerateKey(rand.Reader, "EnochRoot") | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
_ = vkey // give to verifiers | ||
|
||
me, err := note.NewSigner(skey) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
msg, err = note.Sign(n, me) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
os.Stdout.Write(msg) | ||
|
||
// Output: | ||
// If you think cryptography is the answer to your problem, | ||
// then you don't know what your problem is. | ||
// | ||
// — PeterNeumann x08go/ZJkuBS9UG/SffcvIAQxVBtiFupLLr8pAcElZInNIuGUgYN1FFYC2pZSNXgKvqfqdngotpRZb6KE6RyyBwJnAM= | ||
// — EnochRoot rwz+eBzmZa0SO3NbfRGzPCpDckykFXSdeX+MNtCOXm2/5n2tiOHp+vAF1aGrQ5ovTG01oOTGwnWLox33WWd1RvMc+QQ= | ||
} |
Oops, something went wrong.