github.com/glycerine/xcryptossh@v7.0.4+incompatible/testdata_test.go (about) 1 // Copyright 2014 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 // IMPLEMENTATION NOTE: To avoid a package loop, this file is in three places: 6 // ssh/, ssh/agent, and ssh/test/. It should be kept in sync across all three 7 // instances. 8 9 package ssh 10 11 import ( 12 "crypto/rand" 13 "fmt" 14 15 "github.com/glycerine/xcryptossh/testdata" 16 ) 17 18 var ( 19 testPrivateKeys map[string]interface{} 20 testSigners map[string]Signer 21 testPublicKeys map[string]PublicKey 22 ) 23 24 func init() { 25 var err error 26 27 n := len(testdata.PEMBytes) 28 testPrivateKeys = make(map[string]interface{}, n) 29 testSigners = make(map[string]Signer, n) 30 testPublicKeys = make(map[string]PublicKey, n) 31 for t, k := range testdata.PEMBytes { 32 testPrivateKeys[t], err = ParseRawPrivateKey(k) 33 if err != nil { 34 panic(fmt.Sprintf("Unable to parse test key %s: %v", t, err)) 35 } 36 testSigners[t], err = NewSignerFromKey(testPrivateKeys[t]) 37 if err != nil { 38 panic(fmt.Sprintf("Unable to create signer for test key %s: %v", t, err)) 39 } 40 testPublicKeys[t] = testSigners[t].PublicKey() 41 } 42 43 // Create a cert and sign it for use in tests. 44 testCert := &Certificate{ 45 Nonce: []byte{}, // To pass reflect.DeepEqual after marshal & parse, this must be non-nil 46 ValidPrincipals: []string{"gopher1", "gopher2"}, // increases test coverage 47 ValidAfter: 0, // unix epoch 48 ValidBefore: CertTimeInfinity, // The end of currently representable time. 49 Reserved: []byte{}, // To pass reflect.DeepEqual after marshal & parse, this must be non-nil 50 Key: testPublicKeys["ecdsa"], 51 SignatureKey: testPublicKeys["rsa"], 52 Permissions: Permissions{ 53 CriticalOptions: map[string]string{}, 54 Extensions: map[string]string{}, 55 }, 56 } 57 testCert.SignCert(rand.Reader, testSigners["rsa"]) 58 testPrivateKeys["cert"] = testPrivateKeys["ecdsa"] 59 testSigners["cert"], err = NewCertSigner(testCert, testSigners["ecdsa"]) 60 if err != nil { 61 panic(fmt.Sprintf("Unable to create certificate signer: %v", err)) 62 } 63 }