repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
theupdateframework/notary
trustmanager/yubikey/yubikeystore.go
IsAccessible
func IsAccessible() bool { if pkcs11Lib == "" { return false } ctx, session, err := SetupHSMEnv(pkcs11Lib, defaultLoader) if err != nil { return false } defer cleanup(ctx, session) return true }
go
func IsAccessible() bool { if pkcs11Lib == "" { return false } ctx, session, err := SetupHSMEnv(pkcs11Lib, defaultLoader) if err != nil { return false } defer cleanup(ctx, session) return true }
[ "func", "IsAccessible", "(", ")", "bool", "{", "if", "pkcs11Lib", "==", "\"\"", "{", "return", "false", "\n", "}", "\n", "ctx", ",", "session", ",", "err", ":=", "SetupHSMEnv", "(", "pkcs11Lib", ",", "defaultLoader", ")", "\n", "if", "err", "!=", "nil"...
// IsAccessible returns true if a Yubikey can be accessed
[ "IsAccessible", "returns", "true", "if", "a", "Yubikey", "can", "be", "accessed" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L870-L880
train
theupdateframework/notary
tuf/signed/verifiers.go
Verify
func (v Ed25519Verifier) Verify(key data.PublicKey, sig []byte, msg []byte) error { if key.Algorithm() != data.ED25519Key { return ErrInvalidKeyType{} } sigBytes := make([]byte, ed25519.SignatureSize) if len(sig) != ed25519.SignatureSize { logrus.Debugf("signature length is incorrect, must be %d, was %d.", ed25519.SignatureSize, len(sig)) return ErrInvalid } copy(sigBytes, sig) keyBytes := make([]byte, ed25519.PublicKeySize) pub := key.Public() if len(pub) != ed25519.PublicKeySize { logrus.Errorf("public key is incorrect size, must be %d, was %d.", ed25519.PublicKeySize, len(pub)) return ErrInvalidKeyLength{msg: fmt.Sprintf("ed25519 public key must be %d bytes.", ed25519.PublicKeySize)} } n := copy(keyBytes, key.Public()) if n < ed25519.PublicKeySize { logrus.Errorf("failed to copy the key, must have %d bytes, copied %d bytes.", ed25519.PublicKeySize, n) return ErrInvalid } if !ed25519.Verify(ed25519.PublicKey(keyBytes), msg, sigBytes) { logrus.Debugf("failed ed25519 verification") return ErrInvalid } return nil }
go
func (v Ed25519Verifier) Verify(key data.PublicKey, sig []byte, msg []byte) error { if key.Algorithm() != data.ED25519Key { return ErrInvalidKeyType{} } sigBytes := make([]byte, ed25519.SignatureSize) if len(sig) != ed25519.SignatureSize { logrus.Debugf("signature length is incorrect, must be %d, was %d.", ed25519.SignatureSize, len(sig)) return ErrInvalid } copy(sigBytes, sig) keyBytes := make([]byte, ed25519.PublicKeySize) pub := key.Public() if len(pub) != ed25519.PublicKeySize { logrus.Errorf("public key is incorrect size, must be %d, was %d.", ed25519.PublicKeySize, len(pub)) return ErrInvalidKeyLength{msg: fmt.Sprintf("ed25519 public key must be %d bytes.", ed25519.PublicKeySize)} } n := copy(keyBytes, key.Public()) if n < ed25519.PublicKeySize { logrus.Errorf("failed to copy the key, must have %d bytes, copied %d bytes.", ed25519.PublicKeySize, n) return ErrInvalid } if !ed25519.Verify(ed25519.PublicKey(keyBytes), msg, sigBytes) { logrus.Debugf("failed ed25519 verification") return ErrInvalid } return nil }
[ "func", "(", "v", "Ed25519Verifier", ")", "Verify", "(", "key", "data", ".", "PublicKey", ",", "sig", "[", "]", "byte", ",", "msg", "[", "]", "byte", ")", "error", "{", "if", "key", ".", "Algorithm", "(", ")", "!=", "data", ".", "ED25519Key", "{", ...
// Verify checks that an ed25519 signature is valid
[ "Verify", "checks", "that", "an", "ed25519", "signature", "is", "valid" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/signed/verifiers.go#L38-L66
train
theupdateframework/notary
tuf/signed/verifiers.go
Verify
func (v RSAPKCS1v15Verifier) Verify(key data.PublicKey, sig []byte, msg []byte) error { // will return err if keytype is not a recognized RSA type pubKey, err := getRSAPubKey(key) if err != nil { return err } digest := sha256.Sum256(msg) rsaPub, ok := pubKey.(*rsa.PublicKey) if !ok { logrus.Debugf("value was not an RSA public key") return ErrInvalid } if rsaPub.N.BitLen() < minRSAKeySizeBit { logrus.Debugf("RSA keys less than 2048 bits are not acceptable, provided key has length %d.", rsaPub.N.BitLen()) return ErrInvalidKeyLength{msg: fmt.Sprintf("RSA key must be at least %d bits.", minRSAKeySizeBit)} } if len(sig) < minRSAKeySizeByte { logrus.Debugf("RSA keys less than 2048 bits are not acceptable, provided signature has length %d.", len(sig)) return ErrInvalid } if err = rsa.VerifyPKCS1v15(rsaPub, crypto.SHA256, digest[:], sig); err != nil { logrus.Errorf("Failed verification: %s", err.Error()) return ErrInvalid } return nil }
go
func (v RSAPKCS1v15Verifier) Verify(key data.PublicKey, sig []byte, msg []byte) error { // will return err if keytype is not a recognized RSA type pubKey, err := getRSAPubKey(key) if err != nil { return err } digest := sha256.Sum256(msg) rsaPub, ok := pubKey.(*rsa.PublicKey) if !ok { logrus.Debugf("value was not an RSA public key") return ErrInvalid } if rsaPub.N.BitLen() < minRSAKeySizeBit { logrus.Debugf("RSA keys less than 2048 bits are not acceptable, provided key has length %d.", rsaPub.N.BitLen()) return ErrInvalidKeyLength{msg: fmt.Sprintf("RSA key must be at least %d bits.", minRSAKeySizeBit)} } if len(sig) < minRSAKeySizeByte { logrus.Debugf("RSA keys less than 2048 bits are not acceptable, provided signature has length %d.", len(sig)) return ErrInvalid } if err = rsa.VerifyPKCS1v15(rsaPub, crypto.SHA256, digest[:], sig); err != nil { logrus.Errorf("Failed verification: %s", err.Error()) return ErrInvalid } return nil }
[ "func", "(", "v", "RSAPKCS1v15Verifier", ")", "Verify", "(", "key", "data", ".", "PublicKey", ",", "sig", "[", "]", "byte", ",", "msg", "[", "]", "byte", ")", "error", "{", "pubKey", ",", "err", ":=", "getRSAPubKey", "(", "key", ")", "\n", "if", "e...
// Verify does the actual verification
[ "Verify", "does", "the", "actual", "verification" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/signed/verifiers.go#L146-L175
train
theupdateframework/notary
tuf/signed/verifiers.go
Verify
func (v RSAPyCryptoVerifier) Verify(key data.PublicKey, sig []byte, msg []byte) error { digest := sha256.Sum256(msg) if key.Algorithm() != data.RSAKey { return ErrInvalidKeyType{} } k, _ := pem.Decode([]byte(key.Public())) if k == nil { logrus.Debugf("failed to decode PEM-encoded x509 certificate") return ErrInvalid } pub, err := x509.ParsePKIXPublicKey(k.Bytes) if err != nil { logrus.Debugf("failed to parse public key: %s\n", err) return ErrInvalid } return verifyPSS(pub, digest[:], sig) }
go
func (v RSAPyCryptoVerifier) Verify(key data.PublicKey, sig []byte, msg []byte) error { digest := sha256.Sum256(msg) if key.Algorithm() != data.RSAKey { return ErrInvalidKeyType{} } k, _ := pem.Decode([]byte(key.Public())) if k == nil { logrus.Debugf("failed to decode PEM-encoded x509 certificate") return ErrInvalid } pub, err := x509.ParsePKIXPublicKey(k.Bytes) if err != nil { logrus.Debugf("failed to parse public key: %s\n", err) return ErrInvalid } return verifyPSS(pub, digest[:], sig) }
[ "func", "(", "v", "RSAPyCryptoVerifier", ")", "Verify", "(", "key", "data", ".", "PublicKey", ",", "sig", "[", "]", "byte", ",", "msg", "[", "]", "byte", ")", "error", "{", "digest", ":=", "sha256", ".", "Sum256", "(", "msg", ")", "\n", "if", "key"...
// Verify does the actual check. // N.B. We have not been able to make this work in a way that is compatible // with PyCrypto.
[ "Verify", "does", "the", "actual", "check", ".", "N", ".", "B", ".", "We", "have", "not", "been", "able", "to", "make", "this", "work", "in", "a", "way", "that", "is", "compatible", "with", "PyCrypto", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/signed/verifiers.go#L183-L202
train
theupdateframework/notary
signer/keydbstore/keydbstore.go
generatePrivateKey
func generatePrivateKey(algorithm string) (data.PrivateKey, error) { var privKey data.PrivateKey var err error switch algorithm { case data.ECDSAKey: privKey, err = utils.GenerateECDSAKey(rand.Reader) if err != nil { return nil, fmt.Errorf("failed to generate EC key: %v", err) } case data.ED25519Key: privKey, err = utils.GenerateED25519Key(rand.Reader) if err != nil { return nil, fmt.Errorf("failed to generate ED25519 key: %v", err) } default: return nil, fmt.Errorf("private key type not supported for key generation: %s", algorithm) } return privKey, nil }
go
func generatePrivateKey(algorithm string) (data.PrivateKey, error) { var privKey data.PrivateKey var err error switch algorithm { case data.ECDSAKey: privKey, err = utils.GenerateECDSAKey(rand.Reader) if err != nil { return nil, fmt.Errorf("failed to generate EC key: %v", err) } case data.ED25519Key: privKey, err = utils.GenerateED25519Key(rand.Reader) if err != nil { return nil, fmt.Errorf("failed to generate ED25519 key: %v", err) } default: return nil, fmt.Errorf("private key type not supported for key generation: %s", algorithm) } return privKey, nil }
[ "func", "generatePrivateKey", "(", "algorithm", "string", ")", "(", "data", ".", "PrivateKey", ",", "error", ")", "{", "var", "privKey", "data", ".", "PrivateKey", "\n", "var", "err", "error", "\n", "switch", "algorithm", "{", "case", "data", ".", "ECDSAKe...
// helper function to generate private keys for the signer databases - does not implement RSA since that is not // supported by the signer
[ "helper", "function", "to", "generate", "private", "keys", "for", "the", "signer", "databases", "-", "does", "not", "implement", "RSA", "since", "that", "is", "not", "supported", "by", "the", "signer" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/signer/keydbstore/keydbstore.go#L33-L51
train
theupdateframework/notary
tuf/data/serializer.go
Unmarshal
func (c canonicalJSON) Unmarshal(from []byte, to interface{}) error { return json.Unmarshal(from, to) }
go
func (c canonicalJSON) Unmarshal(from []byte, to interface{}) error { return json.Unmarshal(from, to) }
[ "func", "(", "c", "canonicalJSON", ")", "Unmarshal", "(", "from", "[", "]", "byte", ",", "to", "interface", "{", "}", ")", "error", "{", "return", "json", ".", "Unmarshal", "(", "from", ",", "to", ")", "\n", "}" ]
// Unmarshal unmarshals some JSON bytes
[ "Unmarshal", "unmarshals", "some", "JSON", "bytes" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/serializer.go#L27-L29
train
theupdateframework/notary
tuf/data/timestamp.go
IsValidTimestampStructure
func IsValidTimestampStructure(t Timestamp) error { expectedType := TUFTypes[CanonicalTimestampRole] if t.Type != expectedType { return ErrInvalidMetadata{ role: CanonicalTimestampRole, msg: fmt.Sprintf("expected type %s, not %s", expectedType, t.Type)} } if t.Version < 1 { return ErrInvalidMetadata{ role: CanonicalTimestampRole, msg: "version cannot be less than one"} } // Meta is a map of FileMeta, so if the role isn't in the map it returns // an empty FileMeta, which has an empty map, and you can check on keys // from an empty map. // // For now sha256 is required and sha512 is not. if _, ok := t.Meta[CanonicalSnapshotRole.String()].Hashes[notary.SHA256]; !ok { return ErrInvalidMetadata{ role: CanonicalTimestampRole, msg: "missing snapshot sha256 checksum information"} } if err := CheckValidHashStructures(t.Meta[CanonicalSnapshotRole.String()].Hashes); err != nil { return ErrInvalidMetadata{ role: CanonicalTimestampRole, msg: fmt.Sprintf("invalid snapshot checksum information, %v", err)} } return nil }
go
func IsValidTimestampStructure(t Timestamp) error { expectedType := TUFTypes[CanonicalTimestampRole] if t.Type != expectedType { return ErrInvalidMetadata{ role: CanonicalTimestampRole, msg: fmt.Sprintf("expected type %s, not %s", expectedType, t.Type)} } if t.Version < 1 { return ErrInvalidMetadata{ role: CanonicalTimestampRole, msg: "version cannot be less than one"} } // Meta is a map of FileMeta, so if the role isn't in the map it returns // an empty FileMeta, which has an empty map, and you can check on keys // from an empty map. // // For now sha256 is required and sha512 is not. if _, ok := t.Meta[CanonicalSnapshotRole.String()].Hashes[notary.SHA256]; !ok { return ErrInvalidMetadata{ role: CanonicalTimestampRole, msg: "missing snapshot sha256 checksum information"} } if err := CheckValidHashStructures(t.Meta[CanonicalSnapshotRole.String()].Hashes); err != nil { return ErrInvalidMetadata{ role: CanonicalTimestampRole, msg: fmt.Sprintf("invalid snapshot checksum information, %v", err)} } return nil }
[ "func", "IsValidTimestampStructure", "(", "t", "Timestamp", ")", "error", "{", "expectedType", ":=", "TUFTypes", "[", "CanonicalTimestampRole", "]", "\n", "if", "t", ".", "Type", "!=", "expectedType", "{", "return", "ErrInvalidMetadata", "{", "role", ":", "Canon...
// IsValidTimestampStructure returns an error, or nil, depending on whether the content of the struct // is valid for timestamp metadata. This does not check signatures or expiry, just that // the metadata content is valid.
[ "IsValidTimestampStructure", "returns", "an", "error", "or", "nil", "depending", "on", "whether", "the", "content", "of", "the", "struct", "is", "valid", "for", "timestamp", "metadata", ".", "This", "does", "not", "check", "signatures", "or", "expiry", "just", ...
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L27-L54
train
theupdateframework/notary
tuf/data/timestamp.go
NewTimestamp
func NewTimestamp(snapshot *Signed) (*SignedTimestamp, error) { snapshotJSON, err := json.Marshal(snapshot) if err != nil { return nil, err } snapshotMeta, err := NewFileMeta(bytes.NewReader(snapshotJSON), NotaryDefaultHashes...) if err != nil { return nil, err } return &SignedTimestamp{ Signatures: make([]Signature, 0), Signed: Timestamp{ SignedCommon: SignedCommon{ Type: TUFTypes[CanonicalTimestampRole], Version: 0, Expires: DefaultExpires(CanonicalTimestampRole), }, Meta: Files{ CanonicalSnapshotRole.String(): snapshotMeta, }, }, }, nil }
go
func NewTimestamp(snapshot *Signed) (*SignedTimestamp, error) { snapshotJSON, err := json.Marshal(snapshot) if err != nil { return nil, err } snapshotMeta, err := NewFileMeta(bytes.NewReader(snapshotJSON), NotaryDefaultHashes...) if err != nil { return nil, err } return &SignedTimestamp{ Signatures: make([]Signature, 0), Signed: Timestamp{ SignedCommon: SignedCommon{ Type: TUFTypes[CanonicalTimestampRole], Version: 0, Expires: DefaultExpires(CanonicalTimestampRole), }, Meta: Files{ CanonicalSnapshotRole.String(): snapshotMeta, }, }, }, nil }
[ "func", "NewTimestamp", "(", "snapshot", "*", "Signed", ")", "(", "*", "SignedTimestamp", ",", "error", ")", "{", "snapshotJSON", ",", "err", ":=", "json", ".", "Marshal", "(", "snapshot", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",",...
// NewTimestamp initializes a timestamp with an existing snapshot
[ "NewTimestamp", "initializes", "a", "timestamp", "with", "an", "existing", "snapshot" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L57-L79
train
theupdateframework/notary
tuf/data/timestamp.go
ToSigned
func (ts *SignedTimestamp) ToSigned() (*Signed, error) { s, err := defaultSerializer.MarshalCanonical(ts.Signed) if err != nil { return nil, err } signed := json.RawMessage{} err = signed.UnmarshalJSON(s) if err != nil { return nil, err } sigs := make([]Signature, len(ts.Signatures)) copy(sigs, ts.Signatures) return &Signed{ Signatures: sigs, Signed: &signed, }, nil }
go
func (ts *SignedTimestamp) ToSigned() (*Signed, error) { s, err := defaultSerializer.MarshalCanonical(ts.Signed) if err != nil { return nil, err } signed := json.RawMessage{} err = signed.UnmarshalJSON(s) if err != nil { return nil, err } sigs := make([]Signature, len(ts.Signatures)) copy(sigs, ts.Signatures) return &Signed{ Signatures: sigs, Signed: &signed, }, nil }
[ "func", "(", "ts", "*", "SignedTimestamp", ")", "ToSigned", "(", ")", "(", "*", "Signed", ",", "error", ")", "{", "s", ",", "err", ":=", "defaultSerializer", ".", "MarshalCanonical", "(", "ts", ".", "Signed", ")", "\n", "if", "err", "!=", "nil", "{",...
// ToSigned partially serializes a SignedTimestamp such that it can // be signed
[ "ToSigned", "partially", "serializes", "a", "SignedTimestamp", "such", "that", "it", "can", "be", "signed" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L83-L99
train
theupdateframework/notary
tuf/data/timestamp.go
GetSnapshot
func (ts *SignedTimestamp) GetSnapshot() (*FileMeta, error) { snapshotExpected, ok := ts.Signed.Meta[CanonicalSnapshotRole.String()] if !ok { return nil, ErrMissingMeta{Role: CanonicalSnapshotRole.String()} } return &snapshotExpected, nil }
go
func (ts *SignedTimestamp) GetSnapshot() (*FileMeta, error) { snapshotExpected, ok := ts.Signed.Meta[CanonicalSnapshotRole.String()] if !ok { return nil, ErrMissingMeta{Role: CanonicalSnapshotRole.String()} } return &snapshotExpected, nil }
[ "func", "(", "ts", "*", "SignedTimestamp", ")", "GetSnapshot", "(", ")", "(", "*", "FileMeta", ",", "error", ")", "{", "snapshotExpected", ",", "ok", ":=", "ts", ".", "Signed", ".", "Meta", "[", "CanonicalSnapshotRole", ".", "String", "(", ")", "]", "\...
// GetSnapshot gets the expected snapshot metadata hashes in the timestamp metadata, // or nil if it doesn't exist
[ "GetSnapshot", "gets", "the", "expected", "snapshot", "metadata", "hashes", "in", "the", "timestamp", "metadata", "or", "nil", "if", "it", "doesn", "t", "exist" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L103-L109
train
theupdateframework/notary
tuf/data/timestamp.go
MarshalJSON
func (ts *SignedTimestamp) MarshalJSON() ([]byte, error) { signed, err := ts.ToSigned() if err != nil { return nil, err } return defaultSerializer.Marshal(signed) }
go
func (ts *SignedTimestamp) MarshalJSON() ([]byte, error) { signed, err := ts.ToSigned() if err != nil { return nil, err } return defaultSerializer.Marshal(signed) }
[ "func", "(", "ts", "*", "SignedTimestamp", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "signed", ",", "err", ":=", "ts", ".", "ToSigned", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err",...
// MarshalJSON returns the serialized form of SignedTimestamp as bytes
[ "MarshalJSON", "returns", "the", "serialized", "form", "of", "SignedTimestamp", "as", "bytes" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L112-L118
train
theupdateframework/notary
tuf/data/timestamp.go
TimestampFromSigned
func TimestampFromSigned(s *Signed) (*SignedTimestamp, error) { ts := Timestamp{} if err := defaultSerializer.Unmarshal(*s.Signed, &ts); err != nil { return nil, err } if err := IsValidTimestampStructure(ts); err != nil { return nil, err } sigs := make([]Signature, len(s.Signatures)) copy(sigs, s.Signatures) return &SignedTimestamp{ Signatures: sigs, Signed: ts, }, nil }
go
func TimestampFromSigned(s *Signed) (*SignedTimestamp, error) { ts := Timestamp{} if err := defaultSerializer.Unmarshal(*s.Signed, &ts); err != nil { return nil, err } if err := IsValidTimestampStructure(ts); err != nil { return nil, err } sigs := make([]Signature, len(s.Signatures)) copy(sigs, s.Signatures) return &SignedTimestamp{ Signatures: sigs, Signed: ts, }, nil }
[ "func", "TimestampFromSigned", "(", "s", "*", "Signed", ")", "(", "*", "SignedTimestamp", ",", "error", ")", "{", "ts", ":=", "Timestamp", "{", "}", "\n", "if", "err", ":=", "defaultSerializer", ".", "Unmarshal", "(", "*", "s", ".", "Signed", ",", "&",...
// TimestampFromSigned parsed a Signed object into a fully unpacked // SignedTimestamp
[ "TimestampFromSigned", "parsed", "a", "Signed", "object", "into", "a", "fully", "unpacked", "SignedTimestamp" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L122-L136
train
theupdateframework/notary
trustmanager/yubikey/import.go
Set
func (s *YubiImport) Set(name string, bytes []byte) error { block, _ := pem.Decode(bytes) if block == nil { return errors.New("invalid PEM data, could not parse") } role, ok := block.Headers["role"] if !ok { return errors.New("no role found for key") } ki := trustmanager.KeyInfo{ // GUN is ignored by YubiStore Role: data.RoleName(role), } privKey, err := utils.ParsePEMPrivateKey(bytes, "") if err != nil { privKey, _, err = trustmanager.GetPasswdDecryptBytes( s.passRetriever, bytes, name, ki.Role.String(), ) if err != nil { return err } } return s.dest.AddKey(ki, privKey) }
go
func (s *YubiImport) Set(name string, bytes []byte) error { block, _ := pem.Decode(bytes) if block == nil { return errors.New("invalid PEM data, could not parse") } role, ok := block.Headers["role"] if !ok { return errors.New("no role found for key") } ki := trustmanager.KeyInfo{ // GUN is ignored by YubiStore Role: data.RoleName(role), } privKey, err := utils.ParsePEMPrivateKey(bytes, "") if err != nil { privKey, _, err = trustmanager.GetPasswdDecryptBytes( s.passRetriever, bytes, name, ki.Role.String(), ) if err != nil { return err } } return s.dest.AddKey(ki, privKey) }
[ "func", "(", "s", "*", "YubiImport", ")", "Set", "(", "name", "string", ",", "bytes", "[", "]", "byte", ")", "error", "{", "block", ",", "_", ":=", "pem", ".", "Decode", "(", "bytes", ")", "\n", "if", "block", "==", "nil", "{", "return", "errors"...
// Set determines if we are allowed to set the given key on the Yubikey and // calls through to YubiStore.AddKey if it's valid
[ "Set", "determines", "if", "we", "are", "allowed", "to", "set", "the", "given", "key", "on", "the", "Yubikey", "and", "calls", "through", "to", "YubiStore", ".", "AddKey", "if", "it", "s", "valid" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/import.go#L33-L59
train
theupdateframework/notary
server/storage/errors.go
Error
func (err ErrKeyExists) Error() string { return fmt.Sprintf("Error, timestamp key already exists for %s:%s", err.gun, err.role) }
go
func (err ErrKeyExists) Error() string { return fmt.Sprintf("Error, timestamp key already exists for %s:%s", err.gun, err.role) }
[ "func", "(", "err", "ErrKeyExists", ")", "Error", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"Error, timestamp key already exists for %s:%s\"", ",", "err", ".", "gun", ",", "err", ".", "role", ")", "\n", "}" ]
// ErrKeyExists is returned when a key already exists
[ "ErrKeyExists", "is", "returned", "when", "a", "key", "already", "exists" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/errors.go#L30-L32
train
theupdateframework/notary
tuf/data/keys.go
IDs
func (ks KeyList) IDs() []string { keyIDs := make([]string, 0, len(ks)) for _, k := range ks { keyIDs = append(keyIDs, k.ID()) } return keyIDs }
go
func (ks KeyList) IDs() []string { keyIDs := make([]string, 0, len(ks)) for _, k := range ks { keyIDs = append(keyIDs, k.ID()) } return keyIDs }
[ "func", "(", "ks", "KeyList", ")", "IDs", "(", ")", "[", "]", "string", "{", "keyIDs", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "ks", ")", ")", "\n", "for", "_", ",", "k", ":=", "range", "ks", "{", "keyIDs", "=", "a...
// IDs generates a list of the hex encoded key IDs in the KeyList
[ "IDs", "generates", "a", "list", "of", "the", "hex", "encoded", "key", "IDs", "in", "the", "KeyList" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L81-L87
train
theupdateframework/notary
tuf/data/keys.go
NewPublicKey
func NewPublicKey(alg string, public []byte) PublicKey { tk := TUFKey{ Type: alg, Value: KeyPair{ Public: public, }, } return typedPublicKey(tk) }
go
func NewPublicKey(alg string, public []byte) PublicKey { tk := TUFKey{ Type: alg, Value: KeyPair{ Public: public, }, } return typedPublicKey(tk) }
[ "func", "NewPublicKey", "(", "alg", "string", ",", "public", "[", "]", "byte", ")", "PublicKey", "{", "tk", ":=", "TUFKey", "{", "Type", ":", "alg", ",", "Value", ":", "KeyPair", "{", "Public", ":", "public", ",", "}", ",", "}", "\n", "return", "ty...
// NewPublicKey creates a new, correctly typed PublicKey, using the // UnknownPublicKey catchall for unsupported ciphers
[ "NewPublicKey", "creates", "a", "new", "correctly", "typed", "PublicKey", "using", "the", "UnknownPublicKey", "catchall", "for", "unsupported", "ciphers" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L153-L161
train
theupdateframework/notary
tuf/data/keys.go
NewPrivateKey
func NewPrivateKey(pubKey PublicKey, private []byte) (PrivateKey, error) { tk := TUFKey{ Type: pubKey.Algorithm(), Value: KeyPair{ Public: pubKey.Public(), Private: private, // typedPrivateKey moves this value }, } return typedPrivateKey(tk) }
go
func NewPrivateKey(pubKey PublicKey, private []byte) (PrivateKey, error) { tk := TUFKey{ Type: pubKey.Algorithm(), Value: KeyPair{ Public: pubKey.Public(), Private: private, // typedPrivateKey moves this value }, } return typedPrivateKey(tk) }
[ "func", "NewPrivateKey", "(", "pubKey", "PublicKey", ",", "private", "[", "]", "byte", ")", "(", "PrivateKey", ",", "error", ")", "{", "tk", ":=", "TUFKey", "{", "Type", ":", "pubKey", ".", "Algorithm", "(", ")", ",", "Value", ":", "KeyPair", "{", "P...
// NewPrivateKey creates a new, correctly typed PrivateKey, using the // UnknownPrivateKey catchall for unsupported ciphers
[ "NewPrivateKey", "creates", "a", "new", "correctly", "typed", "PrivateKey", "using", "the", "UnknownPrivateKey", "catchall", "for", "unsupported", "ciphers" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L165-L174
train
theupdateframework/notary
tuf/data/keys.go
UnmarshalPublicKey
func UnmarshalPublicKey(data []byte) (PublicKey, error) { var parsed TUFKey err := json.Unmarshal(data, &parsed) if err != nil { return nil, err } return typedPublicKey(parsed), nil }
go
func UnmarshalPublicKey(data []byte) (PublicKey, error) { var parsed TUFKey err := json.Unmarshal(data, &parsed) if err != nil { return nil, err } return typedPublicKey(parsed), nil }
[ "func", "UnmarshalPublicKey", "(", "data", "[", "]", "byte", ")", "(", "PublicKey", ",", "error", ")", "{", "var", "parsed", "TUFKey", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "parsed", ")", "\n", "if", "err", "!=", "nil", ...
// UnmarshalPublicKey is used to parse individual public keys in JSON
[ "UnmarshalPublicKey", "is", "used", "to", "parse", "individual", "public", "keys", "in", "JSON" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L177-L184
train
theupdateframework/notary
tuf/data/keys.go
UnmarshalPrivateKey
func UnmarshalPrivateKey(data []byte) (PrivateKey, error) { var parsed TUFKey err := json.Unmarshal(data, &parsed) if err != nil { return nil, err } return typedPrivateKey(parsed) }
go
func UnmarshalPrivateKey(data []byte) (PrivateKey, error) { var parsed TUFKey err := json.Unmarshal(data, &parsed) if err != nil { return nil, err } return typedPrivateKey(parsed) }
[ "func", "UnmarshalPrivateKey", "(", "data", "[", "]", "byte", ")", "(", "PrivateKey", ",", "error", ")", "{", "var", "parsed", "TUFKey", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "parsed", ")", "\n", "if", "err", "!=", "nil"...
// UnmarshalPrivateKey is used to parse individual private keys in JSON
[ "UnmarshalPrivateKey", "is", "used", "to", "parse", "individual", "private", "keys", "in", "JSON" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L187-L194
train
theupdateframework/notary
tuf/data/keys.go
ID
func (k *TUFKey) ID() string { if k.id == "" { pubK := TUFKey{ Type: k.Algorithm(), Value: KeyPair{ Public: k.Public(), Private: nil, }, } data, err := json.MarshalCanonical(&pubK) if err != nil { logrus.Error("Error generating key ID:", err) } digest := sha256.Sum256(data) k.id = hex.EncodeToString(digest[:]) } return k.id }
go
func (k *TUFKey) ID() string { if k.id == "" { pubK := TUFKey{ Type: k.Algorithm(), Value: KeyPair{ Public: k.Public(), Private: nil, }, } data, err := json.MarshalCanonical(&pubK) if err != nil { logrus.Error("Error generating key ID:", err) } digest := sha256.Sum256(data) k.id = hex.EncodeToString(digest[:]) } return k.id }
[ "func", "(", "k", "*", "TUFKey", ")", "ID", "(", ")", "string", "{", "if", "k", ".", "id", "==", "\"\"", "{", "pubK", ":=", "TUFKey", "{", "Type", ":", "k", ".", "Algorithm", "(", ")", ",", "Value", ":", "KeyPair", "{", "Public", ":", "k", "....
// ID efficiently generates if necessary, and caches the ID of the key
[ "ID", "efficiently", "generates", "if", "necessary", "and", "caches", "the", "ID", "of", "the", "key" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L213-L230
train
theupdateframework/notary
tuf/data/keys.go
NewECDSAPublicKey
func NewECDSAPublicKey(public []byte) *ECDSAPublicKey { return &ECDSAPublicKey{ TUFKey: TUFKey{ Type: ECDSAKey, Value: KeyPair{ Public: public, Private: nil, }, }, } }
go
func NewECDSAPublicKey(public []byte) *ECDSAPublicKey { return &ECDSAPublicKey{ TUFKey: TUFKey{ Type: ECDSAKey, Value: KeyPair{ Public: public, Private: nil, }, }, } }
[ "func", "NewECDSAPublicKey", "(", "public", "[", "]", "byte", ")", "*", "ECDSAPublicKey", "{", "return", "&", "ECDSAPublicKey", "{", "TUFKey", ":", "TUFKey", "{", "Type", ":", "ECDSAKey", ",", "Value", ":", "KeyPair", "{", "Public", ":", "public", ",", "...
// NewECDSAPublicKey initializes a new public key with the ECDSAKey type
[ "NewECDSAPublicKey", "initializes", "a", "new", "public", "key", "with", "the", "ECDSAKey", "type" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L275-L285
train
theupdateframework/notary
tuf/data/keys.go
NewECDSAx509PublicKey
func NewECDSAx509PublicKey(public []byte) *ECDSAx509PublicKey { return &ECDSAx509PublicKey{ TUFKey: TUFKey{ Type: ECDSAx509Key, Value: KeyPair{ Public: public, Private: nil, }, }, } }
go
func NewECDSAx509PublicKey(public []byte) *ECDSAx509PublicKey { return &ECDSAx509PublicKey{ TUFKey: TUFKey{ Type: ECDSAx509Key, Value: KeyPair{ Public: public, Private: nil, }, }, } }
[ "func", "NewECDSAx509PublicKey", "(", "public", "[", "]", "byte", ")", "*", "ECDSAx509PublicKey", "{", "return", "&", "ECDSAx509PublicKey", "{", "TUFKey", ":", "TUFKey", "{", "Type", ":", "ECDSAx509Key", ",", "Value", ":", "KeyPair", "{", "Public", ":", "pub...
// NewECDSAx509PublicKey initializes a new public key with the ECDSAx509Key type
[ "NewECDSAx509PublicKey", "initializes", "a", "new", "public", "key", "with", "the", "ECDSAx509Key", "type" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L288-L298
train
theupdateframework/notary
tuf/data/keys.go
NewRSAPublicKey
func NewRSAPublicKey(public []byte) *RSAPublicKey { return &RSAPublicKey{ TUFKey: TUFKey{ Type: RSAKey, Value: KeyPair{ Public: public, Private: nil, }, }, } }
go
func NewRSAPublicKey(public []byte) *RSAPublicKey { return &RSAPublicKey{ TUFKey: TUFKey{ Type: RSAKey, Value: KeyPair{ Public: public, Private: nil, }, }, } }
[ "func", "NewRSAPublicKey", "(", "public", "[", "]", "byte", ")", "*", "RSAPublicKey", "{", "return", "&", "RSAPublicKey", "{", "TUFKey", ":", "TUFKey", "{", "Type", ":", "RSAKey", ",", "Value", ":", "KeyPair", "{", "Public", ":", "public", ",", "Private"...
// NewRSAPublicKey initializes a new public key with the RSA type
[ "NewRSAPublicKey", "initializes", "a", "new", "public", "key", "with", "the", "RSA", "type" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L301-L311
train
theupdateframework/notary
tuf/data/keys.go
NewRSAx509PublicKey
func NewRSAx509PublicKey(public []byte) *RSAx509PublicKey { return &RSAx509PublicKey{ TUFKey: TUFKey{ Type: RSAx509Key, Value: KeyPair{ Public: public, Private: nil, }, }, } }
go
func NewRSAx509PublicKey(public []byte) *RSAx509PublicKey { return &RSAx509PublicKey{ TUFKey: TUFKey{ Type: RSAx509Key, Value: KeyPair{ Public: public, Private: nil, }, }, } }
[ "func", "NewRSAx509PublicKey", "(", "public", "[", "]", "byte", ")", "*", "RSAx509PublicKey", "{", "return", "&", "RSAx509PublicKey", "{", "TUFKey", ":", "TUFKey", "{", "Type", ":", "RSAx509Key", ",", "Value", ":", "KeyPair", "{", "Public", ":", "public", ...
// NewRSAx509PublicKey initializes a new public key with the RSAx509Key type
[ "NewRSAx509PublicKey", "initializes", "a", "new", "public", "key", "with", "the", "RSAx509Key", "type" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L314-L324
train
theupdateframework/notary
tuf/data/keys.go
NewED25519PublicKey
func NewED25519PublicKey(public []byte) *ED25519PublicKey { return &ED25519PublicKey{ TUFKey: TUFKey{ Type: ED25519Key, Value: KeyPair{ Public: public, Private: nil, }, }, } }
go
func NewED25519PublicKey(public []byte) *ED25519PublicKey { return &ED25519PublicKey{ TUFKey: TUFKey{ Type: ED25519Key, Value: KeyPair{ Public: public, Private: nil, }, }, } }
[ "func", "NewED25519PublicKey", "(", "public", "[", "]", "byte", ")", "*", "ED25519PublicKey", "{", "return", "&", "ED25519PublicKey", "{", "TUFKey", ":", "TUFKey", "{", "Type", ":", "ED25519Key", ",", "Value", ":", "KeyPair", "{", "Public", ":", "public", ...
// NewED25519PublicKey initializes a new public key with the ED25519Key type
[ "NewED25519PublicKey", "initializes", "a", "new", "public", "key", "with", "the", "ED25519Key", "type" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L327-L337
train
theupdateframework/notary
tuf/data/keys.go
NewECDSAPrivateKey
func NewECDSAPrivateKey(public PublicKey, private []byte) (*ECDSAPrivateKey, error) { switch public.(type) { case *ECDSAPublicKey, *ECDSAx509PublicKey: default: return nil, errors.New("invalid public key type provided to NewECDSAPrivateKey") } ecdsaPrivKey, err := x509.ParseECPrivateKey(private) if err != nil { return nil, err } return &ECDSAPrivateKey{ PublicKey: public, privateKey: privateKey{private: private}, signer: signer{signer: ecdsaPrivKey}, }, nil }
go
func NewECDSAPrivateKey(public PublicKey, private []byte) (*ECDSAPrivateKey, error) { switch public.(type) { case *ECDSAPublicKey, *ECDSAx509PublicKey: default: return nil, errors.New("invalid public key type provided to NewECDSAPrivateKey") } ecdsaPrivKey, err := x509.ParseECPrivateKey(private) if err != nil { return nil, err } return &ECDSAPrivateKey{ PublicKey: public, privateKey: privateKey{private: private}, signer: signer{signer: ecdsaPrivKey}, }, nil }
[ "func", "NewECDSAPrivateKey", "(", "public", "PublicKey", ",", "private", "[", "]", "byte", ")", "(", "*", "ECDSAPrivateKey", ",", "error", ")", "{", "switch", "public", ".", "(", "type", ")", "{", "case", "*", "ECDSAPublicKey", ",", "*", "ECDSAx509PublicK...
// NewECDSAPrivateKey initializes a new ECDSA private key
[ "NewECDSAPrivateKey", "initializes", "a", "new", "ECDSA", "private", "key" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L375-L390
train
theupdateframework/notary
tuf/data/keys.go
NewRSAPrivateKey
func NewRSAPrivateKey(public PublicKey, private []byte) (*RSAPrivateKey, error) { switch public.(type) { case *RSAPublicKey, *RSAx509PublicKey: default: return nil, errors.New("invalid public key type provided to NewRSAPrivateKey") } rsaPrivKey, err := x509.ParsePKCS1PrivateKey(private) if err != nil { return nil, err } return &RSAPrivateKey{ PublicKey: public, privateKey: privateKey{private: private}, signer: signer{signer: rsaPrivKey}, }, nil }
go
func NewRSAPrivateKey(public PublicKey, private []byte) (*RSAPrivateKey, error) { switch public.(type) { case *RSAPublicKey, *RSAx509PublicKey: default: return nil, errors.New("invalid public key type provided to NewRSAPrivateKey") } rsaPrivKey, err := x509.ParsePKCS1PrivateKey(private) if err != nil { return nil, err } return &RSAPrivateKey{ PublicKey: public, privateKey: privateKey{private: private}, signer: signer{signer: rsaPrivKey}, }, nil }
[ "func", "NewRSAPrivateKey", "(", "public", "PublicKey", ",", "private", "[", "]", "byte", ")", "(", "*", "RSAPrivateKey", ",", "error", ")", "{", "switch", "public", ".", "(", "type", ")", "{", "case", "*", "RSAPublicKey", ",", "*", "RSAx509PublicKey", "...
// NewRSAPrivateKey initialized a new RSA private key
[ "NewRSAPrivateKey", "initialized", "a", "new", "RSA", "private", "key" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L393-L408
train
theupdateframework/notary
tuf/data/keys.go
NewED25519PrivateKey
func NewED25519PrivateKey(public ED25519PublicKey, private []byte) (*ED25519PrivateKey, error) { return &ED25519PrivateKey{ ED25519PublicKey: public, privateKey: privateKey{private: private}, }, nil }
go
func NewED25519PrivateKey(public ED25519PublicKey, private []byte) (*ED25519PrivateKey, error) { return &ED25519PrivateKey{ ED25519PublicKey: public, privateKey: privateKey{private: private}, }, nil }
[ "func", "NewED25519PrivateKey", "(", "public", "ED25519PublicKey", ",", "private", "[", "]", "byte", ")", "(", "*", "ED25519PrivateKey", ",", "error", ")", "{", "return", "&", "ED25519PrivateKey", "{", "ED25519PublicKey", ":", "public", ",", "privateKey", ":", ...
// NewED25519PrivateKey initialized a new ED25519 private key
[ "NewED25519PrivateKey", "initialized", "a", "new", "ED25519", "private", "key" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L411-L416
train
theupdateframework/notary
tuf/data/keys.go
Sign
func (k ECDSAPrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error) { ecdsaPrivKey, ok := k.CryptoSigner().(*ecdsa.PrivateKey) if !ok { return nil, errors.New("signer was based on the wrong key type") } hashed := sha256.Sum256(msg) sigASN1, err := ecdsaPrivKey.Sign(rand, hashed[:], opts) if err != nil { return nil, err } sig := ecdsaSig{} _, err = asn1.Unmarshal(sigASN1, &sig) if err != nil { return nil, err } rBytes, sBytes := sig.R.Bytes(), sig.S.Bytes() octetLength := (ecdsaPrivKey.Params().BitSize + 7) >> 3 // MUST include leading zeros in the output rBuf := make([]byte, octetLength-len(rBytes), octetLength) sBuf := make([]byte, octetLength-len(sBytes), octetLength) rBuf = append(rBuf, rBytes...) sBuf = append(sBuf, sBytes...) return append(rBuf, sBuf...), nil }
go
func (k ECDSAPrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error) { ecdsaPrivKey, ok := k.CryptoSigner().(*ecdsa.PrivateKey) if !ok { return nil, errors.New("signer was based on the wrong key type") } hashed := sha256.Sum256(msg) sigASN1, err := ecdsaPrivKey.Sign(rand, hashed[:], opts) if err != nil { return nil, err } sig := ecdsaSig{} _, err = asn1.Unmarshal(sigASN1, &sig) if err != nil { return nil, err } rBytes, sBytes := sig.R.Bytes(), sig.S.Bytes() octetLength := (ecdsaPrivKey.Params().BitSize + 7) >> 3 // MUST include leading zeros in the output rBuf := make([]byte, octetLength-len(rBytes), octetLength) sBuf := make([]byte, octetLength-len(sBytes), octetLength) rBuf = append(rBuf, rBytes...) sBuf = append(sBuf, sBytes...) return append(rBuf, sBuf...), nil }
[ "func", "(", "k", "ECDSAPrivateKey", ")", "Sign", "(", "rand", "io", ".", "Reader", ",", "msg", "[", "]", "byte", ",", "opts", "crypto", ".", "SignerOpts", ")", "(", "signature", "[", "]", "byte", ",", "err", "error", ")", "{", "ecdsaPrivKey", ",", ...
// Sign creates an ecdsa signature
[ "Sign", "creates", "an", "ecdsa", "signature" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L445-L471
train
theupdateframework/notary
tuf/data/keys.go
Sign
func (k RSAPrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error) { hashed := sha256.Sum256(msg) if opts == nil { opts = &rsa.PSSOptions{ SaltLength: rsa.PSSSaltLengthEqualsHash, Hash: crypto.SHA256, } } return k.CryptoSigner().Sign(rand, hashed[:], opts) }
go
func (k RSAPrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error) { hashed := sha256.Sum256(msg) if opts == nil { opts = &rsa.PSSOptions{ SaltLength: rsa.PSSSaltLengthEqualsHash, Hash: crypto.SHA256, } } return k.CryptoSigner().Sign(rand, hashed[:], opts) }
[ "func", "(", "k", "RSAPrivateKey", ")", "Sign", "(", "rand", "io", ".", "Reader", ",", "msg", "[", "]", "byte", ",", "opts", "crypto", ".", "SignerOpts", ")", "(", "signature", "[", "]", "byte", ",", "err", "error", ")", "{", "hashed", ":=", "sha25...
// Sign creates an rsa signature
[ "Sign", "creates", "an", "rsa", "signature" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L474-L483
train
theupdateframework/notary
tuf/data/keys.go
Sign
func (k ED25519PrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error) { priv := make([]byte, ed25519.PrivateKeySize) // The ed25519 key is serialized as public key then private key, so just use private key here. copy(priv, k.private[ed25519.PublicKeySize:]) return ed25519.Sign(ed25519.PrivateKey(priv), msg)[:], nil }
go
func (k ED25519PrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error) { priv := make([]byte, ed25519.PrivateKeySize) // The ed25519 key is serialized as public key then private key, so just use private key here. copy(priv, k.private[ed25519.PublicKeySize:]) return ed25519.Sign(ed25519.PrivateKey(priv), msg)[:], nil }
[ "func", "(", "k", "ED25519PrivateKey", ")", "Sign", "(", "rand", "io", ".", "Reader", ",", "msg", "[", "]", "byte", ",", "opts", "crypto", ".", "SignerOpts", ")", "(", "signature", "[", "]", "byte", ",", "err", "error", ")", "{", "priv", ":=", "mak...
// Sign creates an ed25519 signature
[ "Sign", "creates", "an", "ed25519", "signature" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L486-L491
train
theupdateframework/notary
tuf/data/keys.go
Sign
func (k UnknownPrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error) { return nil, errors.New("unknown key type, cannot sign") }
go
func (k UnknownPrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error) { return nil, errors.New("unknown key type, cannot sign") }
[ "func", "(", "k", "UnknownPrivateKey", ")", "Sign", "(", "rand", "io", ".", "Reader", ",", "msg", "[", "]", "byte", ",", "opts", "crypto", ".", "SignerOpts", ")", "(", "signature", "[", "]", "byte", ",", "err", "error", ")", "{", "return", "nil", "...
// Sign on an UnknownPrivateKey raises an error because the client does not // know how to sign with this key type.
[ "Sign", "on", "an", "UnknownPrivateKey", "raises", "an", "error", "because", "the", "client", "does", "not", "know", "how", "to", "sign", "with", "this", "key", "type", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L495-L497
train
theupdateframework/notary
tuf/data/keys.go
PublicKeyFromPrivate
func PublicKeyFromPrivate(pk PrivateKey) PublicKey { return typedPublicKey(TUFKey{ Type: pk.Algorithm(), Value: KeyPair{ Public: pk.Public(), Private: nil, }, }) }
go
func PublicKeyFromPrivate(pk PrivateKey) PublicKey { return typedPublicKey(TUFKey{ Type: pk.Algorithm(), Value: KeyPair{ Public: pk.Public(), Private: nil, }, }) }
[ "func", "PublicKeyFromPrivate", "(", "pk", "PrivateKey", ")", "PublicKey", "{", "return", "typedPublicKey", "(", "TUFKey", "{", "Type", ":", "pk", ".", "Algorithm", "(", ")", ",", "Value", ":", "KeyPair", "{", "Public", ":", "pk", ".", "Public", "(", ")"...
// PublicKeyFromPrivate returns a new TUFKey based on a private key, with // the private key bytes guaranteed to be nil.
[ "PublicKeyFromPrivate", "returns", "a", "new", "TUFKey", "based", "on", "a", "private", "key", "with", "the", "private", "key", "bytes", "guaranteed", "to", "be", "nil", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L521-L529
train
theupdateframework/notary
cmd/notary/prettyprint.go
prettyPrintKeys
func prettyPrintKeys(keyStores []trustmanager.KeyStore, writer io.Writer) { var info []keyInfo for _, store := range keyStores { for keyID, keyIDInfo := range store.ListKeys() { info = append(info, keyInfo{ role: keyIDInfo.Role, location: store.Name(), gun: keyIDInfo.Gun, keyID: keyID, }) } } if len(info) == 0 { writer.Write([]byte("No signing keys found.\n")) return } sort.Stable(keyInfoSorter(info)) tw := initTabWriter([]string{"ROLE", "GUN", "KEY ID", "LOCATION"}, writer) for _, oneKeyInfo := range info { fmt.Fprintf( tw, fourItemRow, oneKeyInfo.role, truncateWithEllipsis(oneKeyInfo.gun.String(), maxGUNWidth, true), oneKeyInfo.keyID, truncateWithEllipsis(oneKeyInfo.location, maxLocWidth, true), ) } tw.Flush() }
go
func prettyPrintKeys(keyStores []trustmanager.KeyStore, writer io.Writer) { var info []keyInfo for _, store := range keyStores { for keyID, keyIDInfo := range store.ListKeys() { info = append(info, keyInfo{ role: keyIDInfo.Role, location: store.Name(), gun: keyIDInfo.Gun, keyID: keyID, }) } } if len(info) == 0 { writer.Write([]byte("No signing keys found.\n")) return } sort.Stable(keyInfoSorter(info)) tw := initTabWriter([]string{"ROLE", "GUN", "KEY ID", "LOCATION"}, writer) for _, oneKeyInfo := range info { fmt.Fprintf( tw, fourItemRow, oneKeyInfo.role, truncateWithEllipsis(oneKeyInfo.gun.String(), maxGUNWidth, true), oneKeyInfo.keyID, truncateWithEllipsis(oneKeyInfo.location, maxLocWidth, true), ) } tw.Flush() }
[ "func", "prettyPrintKeys", "(", "keyStores", "[", "]", "trustmanager", ".", "KeyStore", ",", "writer", "io", ".", "Writer", ")", "{", "var", "info", "[", "]", "keyInfo", "\n", "for", "_", ",", "store", ":=", "range", "keyStores", "{", "for", "keyID", "...
// Given a list of KeyStores in order of listing preference, pretty-prints the // root keys and then the signing keys.
[ "Given", "a", "list", "of", "KeyStores", "in", "order", "of", "listing", "preference", "pretty", "-", "prints", "the", "root", "keys", "and", "then", "the", "signing", "keys", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/cmd/notary/prettyprint.go#L98-L132
train
theupdateframework/notary
cmd/notary/prettyprint.go
prettyPrintTargets
func prettyPrintTargets(ts []*client.TargetWithRole, writer io.Writer) { if len(ts) == 0 { writer.Write([]byte("\nNo targets present in this repository.\n\n")) return } sort.Stable(targetsSorter(ts)) tw := initTabWriter([]string{"NAME", "DIGEST", "SIZE (BYTES)", "ROLE"}, writer) for _, t := range ts { fmt.Fprintf( tw, fourItemRow, t.Name, hex.EncodeToString(t.Hashes["sha256"]), fmt.Sprintf("%d", t.Length), t.Role, ) } tw.Flush() }
go
func prettyPrintTargets(ts []*client.TargetWithRole, writer io.Writer) { if len(ts) == 0 { writer.Write([]byte("\nNo targets present in this repository.\n\n")) return } sort.Stable(targetsSorter(ts)) tw := initTabWriter([]string{"NAME", "DIGEST", "SIZE (BYTES)", "ROLE"}, writer) for _, t := range ts { fmt.Fprintf( tw, fourItemRow, t.Name, hex.EncodeToString(t.Hashes["sha256"]), fmt.Sprintf("%d", t.Length), t.Role, ) } tw.Flush() }
[ "func", "prettyPrintTargets", "(", "ts", "[", "]", "*", "client", ".", "TargetWithRole", ",", "writer", "io", ".", "Writer", ")", "{", "if", "len", "(", "ts", ")", "==", "0", "{", "writer", ".", "Write", "(", "[", "]", "byte", "(", "\"\\nNo targets p...
// Pretty-prints the sorted list of TargetWithRoles.
[ "Pretty", "-", "prints", "the", "sorted", "list", "of", "TargetWithRoles", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/cmd/notary/prettyprint.go#L155-L176
train
theupdateframework/notary
cmd/notary/prettyprint.go
prettyPrintRoles
func prettyPrintRoles(rs []data.Role, writer io.Writer, roleType string) { if len(rs) == 0 { writer.Write([]byte(fmt.Sprintf("\nNo %s present in this repository.\n\n", roleType))) return } // this sorter works for Role types sort.Stable(roleSorter(rs)) tw := initTabWriter([]string{"ROLE", "PATHS", "KEY IDS", "THRESHOLD"}, writer) for _, r := range rs { var path, kid string pp := prettyPaths(r.Paths) if len(pp) > 0 { path = pp[0] } if len(r.KeyIDs) > 0 { kid = r.KeyIDs[0] } fmt.Fprintf( tw, fourItemRow, r.Name, path, kid, fmt.Sprintf("%v", r.Threshold), ) printExtraRoleRows(tw, pp, r.KeyIDs) } tw.Flush() }
go
func prettyPrintRoles(rs []data.Role, writer io.Writer, roleType string) { if len(rs) == 0 { writer.Write([]byte(fmt.Sprintf("\nNo %s present in this repository.\n\n", roleType))) return } // this sorter works for Role types sort.Stable(roleSorter(rs)) tw := initTabWriter([]string{"ROLE", "PATHS", "KEY IDS", "THRESHOLD"}, writer) for _, r := range rs { var path, kid string pp := prettyPaths(r.Paths) if len(pp) > 0 { path = pp[0] } if len(r.KeyIDs) > 0 { kid = r.KeyIDs[0] } fmt.Fprintf( tw, fourItemRow, r.Name, path, kid, fmt.Sprintf("%v", r.Threshold), ) printExtraRoleRows(tw, pp, r.KeyIDs) } tw.Flush() }
[ "func", "prettyPrintRoles", "(", "rs", "[", "]", "data", ".", "Role", ",", "writer", "io", ".", "Writer", ",", "roleType", "string", ")", "{", "if", "len", "(", "rs", ")", "==", "0", "{", "writer", ".", "Write", "(", "[", "]", "byte", "(", "fmt",...
// Pretty-prints the list of provided Roles
[ "Pretty", "-", "prints", "the", "list", "of", "provided", "Roles" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/cmd/notary/prettyprint.go#L179-L210
train
theupdateframework/notary
cmd/notary/prettyprint.go
prettyPaths
func prettyPaths(paths []string) []string { // sort paths first sort.Strings(paths) pp := make([]string, 0, len(paths)) for _, path := range paths { // manually escape "" and designate that it is all paths with an extra print <all paths> if path == "" { path = "\"\" <all paths>" } pp = append(pp, path) } return pp }
go
func prettyPaths(paths []string) []string { // sort paths first sort.Strings(paths) pp := make([]string, 0, len(paths)) for _, path := range paths { // manually escape "" and designate that it is all paths with an extra print <all paths> if path == "" { path = "\"\" <all paths>" } pp = append(pp, path) } return pp }
[ "func", "prettyPaths", "(", "paths", "[", "]", "string", ")", "[", "]", "string", "{", "sort", ".", "Strings", "(", "paths", ")", "\n", "pp", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "paths", ")", ")", "\n", "for", "_",...
// Pretty-formats a list of delegation paths, and ensures the empty string is printed as "" in the console
[ "Pretty", "-", "formats", "a", "list", "of", "delegation", "paths", "and", "ensures", "the", "empty", "string", "is", "printed", "as", "in", "the", "console" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/cmd/notary/prettyprint.go#L239-L251
train
theupdateframework/notary
client/helpers.go
getRemoteStore
func getRemoteStore(baseURL string, gun data.GUN, rt http.RoundTripper) (store.RemoteStore, error) { s, err := store.NewHTTPStore( baseURL+"/v2/"+gun.String()+"/_trust/tuf/", "", "json", "key", rt, ) if err != nil { return store.OfflineStore{}, err } return s, nil }
go
func getRemoteStore(baseURL string, gun data.GUN, rt http.RoundTripper) (store.RemoteStore, error) { s, err := store.NewHTTPStore( baseURL+"/v2/"+gun.String()+"/_trust/tuf/", "", "json", "key", rt, ) if err != nil { return store.OfflineStore{}, err } return s, nil }
[ "func", "getRemoteStore", "(", "baseURL", "string", ",", "gun", "data", ".", "GUN", ",", "rt", "http", ".", "RoundTripper", ")", "(", "store", ".", "RemoteStore", ",", "error", ")", "{", "s", ",", "err", ":=", "store", ".", "NewHTTPStore", "(", "baseUR...
// Use this to initialize remote HTTPStores from the config settings
[ "Use", "this", "to", "initialize", "remote", "HTTPStores", "from", "the", "config", "settings" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/helpers.go#L19-L31
train
theupdateframework/notary
client/helpers.go
getRemoteKey
func getRemoteKey(role data.RoleName, remote store.RemoteStore) (data.PublicKey, error) { rawPubKey, err := remote.GetKey(role) if err != nil { return nil, err } pubKey, err := data.UnmarshalPublicKey(rawPubKey) if err != nil { return nil, err } return pubKey, nil }
go
func getRemoteKey(role data.RoleName, remote store.RemoteStore) (data.PublicKey, error) { rawPubKey, err := remote.GetKey(role) if err != nil { return nil, err } pubKey, err := data.UnmarshalPublicKey(rawPubKey) if err != nil { return nil, err } return pubKey, nil }
[ "func", "getRemoteKey", "(", "role", "data", ".", "RoleName", ",", "remote", "store", ".", "RemoteStore", ")", "(", "data", ".", "PublicKey", ",", "error", ")", "{", "rawPubKey", ",", "err", ":=", "remote", ".", "GetKey", "(", "role", ")", "\n", "if", ...
// Fetches a public key from a remote store, given a gun and role
[ "Fetches", "a", "public", "key", "from", "a", "remote", "store", "given", "a", "gun", "and", "role" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/helpers.go#L222-L234
train
theupdateframework/notary
client/helpers.go
rotateRemoteKey
func rotateRemoteKey(role data.RoleName, remote store.RemoteStore) (data.PublicKey, error) { rawPubKey, err := remote.RotateKey(role) if err != nil { return nil, err } pubKey, err := data.UnmarshalPublicKey(rawPubKey) if err != nil { return nil, err } return pubKey, nil }
go
func rotateRemoteKey(role data.RoleName, remote store.RemoteStore) (data.PublicKey, error) { rawPubKey, err := remote.RotateKey(role) if err != nil { return nil, err } pubKey, err := data.UnmarshalPublicKey(rawPubKey) if err != nil { return nil, err } return pubKey, nil }
[ "func", "rotateRemoteKey", "(", "role", "data", ".", "RoleName", ",", "remote", "store", ".", "RemoteStore", ")", "(", "data", ".", "PublicKey", ",", "error", ")", "{", "rawPubKey", ",", "err", ":=", "remote", ".", "RotateKey", "(", "role", ")", "\n", ...
// Rotates a private key in a remote store and returns the public key component
[ "Rotates", "a", "private", "key", "in", "a", "remote", "store", "and", "returns", "the", "public", "key", "component" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/helpers.go#L237-L249
train
theupdateframework/notary
client/helpers.go
serializeCanonicalRole
func serializeCanonicalRole(tufRepo *tuf.Repo, role data.RoleName, extraSigningKeys data.KeyList) (out []byte, err error) { var s *data.Signed switch { case role == data.CanonicalRootRole: s, err = tufRepo.SignRoot(data.DefaultExpires(role), extraSigningKeys) case role == data.CanonicalSnapshotRole: s, err = tufRepo.SignSnapshot(data.DefaultExpires(role)) case tufRepo.Targets[role] != nil: s, err = tufRepo.SignTargets( role, data.DefaultExpires(data.CanonicalTargetsRole)) default: err = fmt.Errorf("%s not supported role to sign on the client", role) } if err != nil { return } return json.Marshal(s) }
go
func serializeCanonicalRole(tufRepo *tuf.Repo, role data.RoleName, extraSigningKeys data.KeyList) (out []byte, err error) { var s *data.Signed switch { case role == data.CanonicalRootRole: s, err = tufRepo.SignRoot(data.DefaultExpires(role), extraSigningKeys) case role == data.CanonicalSnapshotRole: s, err = tufRepo.SignSnapshot(data.DefaultExpires(role)) case tufRepo.Targets[role] != nil: s, err = tufRepo.SignTargets( role, data.DefaultExpires(data.CanonicalTargetsRole)) default: err = fmt.Errorf("%s not supported role to sign on the client", role) } if err != nil { return } return json.Marshal(s) }
[ "func", "serializeCanonicalRole", "(", "tufRepo", "*", "tuf", ".", "Repo", ",", "role", "data", ".", "RoleName", ",", "extraSigningKeys", "data", ".", "KeyList", ")", "(", "out", "[", "]", "byte", ",", "err", "error", ")", "{", "var", "s", "*", "data",...
// signs and serializes the metadata for a canonical role in a TUF repo to JSON
[ "signs", "and", "serializes", "the", "metadata", "for", "a", "canonical", "role", "in", "a", "TUF", "repo", "to", "JSON" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/helpers.go#L252-L271
train
theupdateframework/notary
server/handlers/changefeed.go
Changefeed
func Changefeed(ctx context.Context, w http.ResponseWriter, r *http.Request) error { var ( vars = mux.Vars(r) logger = ctxu.GetLogger(ctx) qs = r.URL.Query() gun = vars["gun"] changeID = qs.Get("change_id") store, records, err = checkChangefeedInputs(logger, ctx.Value(notary.CtxKeyMetaStore), qs.Get("records")) ) if err != nil { // err already logged and in correct format. return err } out, err := changefeed(logger, store, gun, changeID, records) if err == nil { w.Write(out) } return err }
go
func Changefeed(ctx context.Context, w http.ResponseWriter, r *http.Request) error { var ( vars = mux.Vars(r) logger = ctxu.GetLogger(ctx) qs = r.URL.Query() gun = vars["gun"] changeID = qs.Get("change_id") store, records, err = checkChangefeedInputs(logger, ctx.Value(notary.CtxKeyMetaStore), qs.Get("records")) ) if err != nil { // err already logged and in correct format. return err } out, err := changefeed(logger, store, gun, changeID, records) if err == nil { w.Write(out) } return err }
[ "func", "Changefeed", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "var", "(", "vars", "=", "mux", ".", "Vars", "(", "r", ")", "\n", "logger", "=", "ctxu",...
// Changefeed returns a list of changes according to the provided filters
[ "Changefeed", "returns", "a", "list", "of", "changes", "according", "to", "the", "provided", "filters" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/handlers/changefeed.go#L24-L42
train
theupdateframework/notary
storage/rethinkdb/bootstrap.go
SetupDB
func SetupDB(session *gorethink.Session, dbName string, tables []Table) error { if err := makeDB(session, dbName); err != nil { return fmt.Errorf("unable to create database: %s", err) } cursor, err := gorethink.DB("rethinkdb").Table("server_config").Count().Run(session) if err != nil { return fmt.Errorf("unable to query db server config: %s", err) } var replicaCount uint if err := cursor.One(&replicaCount); err != nil { return fmt.Errorf("unable to scan db server config count: %s", err) } for _, table := range tables { if err = table.create(session, dbName, replicaCount); err != nil { return fmt.Errorf("unable to create table %q: %s", table.Name, err) } } return nil }
go
func SetupDB(session *gorethink.Session, dbName string, tables []Table) error { if err := makeDB(session, dbName); err != nil { return fmt.Errorf("unable to create database: %s", err) } cursor, err := gorethink.DB("rethinkdb").Table("server_config").Count().Run(session) if err != nil { return fmt.Errorf("unable to query db server config: %s", err) } var replicaCount uint if err := cursor.One(&replicaCount); err != nil { return fmt.Errorf("unable to scan db server config count: %s", err) } for _, table := range tables { if err = table.create(session, dbName, replicaCount); err != nil { return fmt.Errorf("unable to create table %q: %s", table.Name, err) } } return nil }
[ "func", "SetupDB", "(", "session", "*", "gorethink", ".", "Session", ",", "dbName", "string", ",", "tables", "[", "]", "Table", ")", "error", "{", "if", "err", ":=", "makeDB", "(", "session", ",", "dbName", ")", ";", "err", "!=", "nil", "{", "return"...
// SetupDB handles creating the database and creating all tables and indexes.
[ "SetupDB", "handles", "creating", "the", "database", "and", "creating", "all", "tables", "and", "indexes", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/storage/rethinkdb/bootstrap.go#L146-L168
train
theupdateframework/notary
storage/rethinkdb/bootstrap.go
CreateAndGrantDBUser
func CreateAndGrantDBUser(session *gorethink.Session, dbName, username, password string) error { var err error logrus.Debugf("creating user %s for db %s", username, dbName) // If the password is empty, pass false to the password parameter if password == "" { err = gorethink.DB("rethinkdb").Table("users").Insert(map[string]interface{}{ "id": username, "password": false, }).Exec(session) } else { err = gorethink.DB("rethinkdb").Table("users").Insert(map[string]string{ "id": username, "password": password, }).Exec(session) } if err != nil { return fmt.Errorf("unable to add user %s to rethinkdb users table: %s", username, err) } // Grant read and write permission return gorethink.DB(dbName).Grant(username, map[string]bool{ "read": true, "write": true, }).Exec(session) }
go
func CreateAndGrantDBUser(session *gorethink.Session, dbName, username, password string) error { var err error logrus.Debugf("creating user %s for db %s", username, dbName) // If the password is empty, pass false to the password parameter if password == "" { err = gorethink.DB("rethinkdb").Table("users").Insert(map[string]interface{}{ "id": username, "password": false, }).Exec(session) } else { err = gorethink.DB("rethinkdb").Table("users").Insert(map[string]string{ "id": username, "password": password, }).Exec(session) } if err != nil { return fmt.Errorf("unable to add user %s to rethinkdb users table: %s", username, err) } // Grant read and write permission return gorethink.DB(dbName).Grant(username, map[string]bool{ "read": true, "write": true, }).Exec(session) }
[ "func", "CreateAndGrantDBUser", "(", "session", "*", "gorethink", ".", "Session", ",", "dbName", ",", "username", ",", "password", "string", ")", "error", "{", "var", "err", "error", "\n", "logrus", ".", "Debugf", "(", "\"creating user %s for db %s\"", ",", "u...
// CreateAndGrantDBUser handles creating a rethink user and granting it permissions to the provided db.
[ "CreateAndGrantDBUser", "handles", "creating", "a", "rethink", "user", "and", "granting", "it", "permissions", "to", "the", "provided", "db", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/storage/rethinkdb/bootstrap.go#L171-L196
train
theupdateframework/notary
utils/configuration.go
GetPathRelativeToConfig
func GetPathRelativeToConfig(configuration *viper.Viper, key string) string { configFile := configuration.ConfigFileUsed() p := configuration.GetString(key) if p == "" || filepath.IsAbs(p) { return p } return filepath.Clean(filepath.Join(filepath.Dir(configFile), p)) }
go
func GetPathRelativeToConfig(configuration *viper.Viper, key string) string { configFile := configuration.ConfigFileUsed() p := configuration.GetString(key) if p == "" || filepath.IsAbs(p) { return p } return filepath.Clean(filepath.Join(filepath.Dir(configFile), p)) }
[ "func", "GetPathRelativeToConfig", "(", "configuration", "*", "viper", ".", "Viper", ",", "key", "string", ")", "string", "{", "configFile", ":=", "configuration", ".", "ConfigFileUsed", "(", ")", "\n", "p", ":=", "configuration", ".", "GetString", "(", "key",...
// GetPathRelativeToConfig gets a configuration key which is a path, and if // it is not empty or an absolute path, returns the absolute path relative // to the configuration file
[ "GetPathRelativeToConfig", "gets", "a", "configuration", "key", "which", "is", "a", "path", "and", "if", "it", "is", "not", "empty", "or", "an", "absolute", "path", "returns", "the", "absolute", "path", "relative", "to", "the", "configuration", "file" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/configuration.go#L43-L50
train
theupdateframework/notary
utils/configuration.go
ParseLogLevel
func ParseLogLevel(configuration *viper.Viper, defaultLevel logrus.Level) ( logrus.Level, error) { logStr := configuration.GetString("logging.level") if logStr == "" { return defaultLevel, nil } return logrus.ParseLevel(logStr) }
go
func ParseLogLevel(configuration *viper.Viper, defaultLevel logrus.Level) ( logrus.Level, error) { logStr := configuration.GetString("logging.level") if logStr == "" { return defaultLevel, nil } return logrus.ParseLevel(logStr) }
[ "func", "ParseLogLevel", "(", "configuration", "*", "viper", ".", "Viper", ",", "defaultLevel", "logrus", ".", "Level", ")", "(", "logrus", ".", "Level", ",", "error", ")", "{", "logStr", ":=", "configuration", ".", "GetString", "(", "\"logging.level\"", ")"...
// ParseLogLevel tries to parse out a log level from a Viper. If there is no // configuration, defaults to the provided error level
[ "ParseLogLevel", "tries", "to", "parse", "out", "a", "log", "level", "from", "a", "Viper", ".", "If", "there", "is", "no", "configuration", "defaults", "to", "the", "provided", "error", "level" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/configuration.go#L84-L92
train
theupdateframework/notary
utils/configuration.go
ParseBugsnag
func ParseBugsnag(configuration *viper.Viper) (*bugsnag.Configuration, error) { // can't unmarshal because we can't add tags to the bugsnag.Configuration // struct bugconf := bugsnag.Configuration{ APIKey: configuration.GetString("reporting.bugsnag.api_key"), ReleaseStage: configuration.GetString("reporting.bugsnag.release_stage"), Endpoint: configuration.GetString("reporting.bugsnag.endpoint"), } if bugconf.APIKey == "" && bugconf.ReleaseStage == "" && bugconf.Endpoint == "" { return nil, nil } if bugconf.APIKey == "" { return nil, fmt.Errorf("must provide an API key for bugsnag") } return &bugconf, nil }
go
func ParseBugsnag(configuration *viper.Viper) (*bugsnag.Configuration, error) { // can't unmarshal because we can't add tags to the bugsnag.Configuration // struct bugconf := bugsnag.Configuration{ APIKey: configuration.GetString("reporting.bugsnag.api_key"), ReleaseStage: configuration.GetString("reporting.bugsnag.release_stage"), Endpoint: configuration.GetString("reporting.bugsnag.endpoint"), } if bugconf.APIKey == "" && bugconf.ReleaseStage == "" && bugconf.Endpoint == "" { return nil, nil } if bugconf.APIKey == "" { return nil, fmt.Errorf("must provide an API key for bugsnag") } return &bugconf, nil }
[ "func", "ParseBugsnag", "(", "configuration", "*", "viper", ".", "Viper", ")", "(", "*", "bugsnag", ".", "Configuration", ",", "error", ")", "{", "bugconf", ":=", "bugsnag", ".", "Configuration", "{", "APIKey", ":", "configuration", ".", "GetString", "(", ...
// ParseBugsnag tries to parse out a Bugsnag Configuration from a Viper. // If no values are provided, returns a nil pointer.
[ "ParseBugsnag", "tries", "to", "parse", "out", "a", "Bugsnag", "Configuration", "from", "a", "Viper", ".", "If", "no", "values", "are", "provided", "returns", "a", "nil", "pointer", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/configuration.go#L183-L198
train
theupdateframework/notary
utils/configuration.go
SetUpBugsnag
func SetUpBugsnag(config *bugsnag.Configuration) error { if config != nil { bugsnag.Configure(*config) hook, err := bugsnag_hook.NewBugsnagHook() if err != nil { return err } logrus.AddHook(hook) logrus.Debug("Adding logrus hook for Bugsnag") } return nil }
go
func SetUpBugsnag(config *bugsnag.Configuration) error { if config != nil { bugsnag.Configure(*config) hook, err := bugsnag_hook.NewBugsnagHook() if err != nil { return err } logrus.AddHook(hook) logrus.Debug("Adding logrus hook for Bugsnag") } return nil }
[ "func", "SetUpBugsnag", "(", "config", "*", "bugsnag", ".", "Configuration", ")", "error", "{", "if", "config", "!=", "nil", "{", "bugsnag", ".", "Configure", "(", "*", "config", ")", "\n", "hook", ",", "err", ":=", "bugsnag_hook", ".", "NewBugsnagHook", ...
// SetUpBugsnag configures bugsnag and sets up a logrus hook
[ "SetUpBugsnag", "configures", "bugsnag", "and", "sets", "up", "a", "logrus", "hook" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/configuration.go#L211-L222
train
theupdateframework/notary
utils/configuration.go
ParseViper
func ParseViper(v *viper.Viper, configFile string) error { filename := filepath.Base(configFile) ext := filepath.Ext(configFile) configPath := filepath.Dir(configFile) v.SetConfigType(strings.TrimPrefix(ext, ".")) v.SetConfigName(strings.TrimSuffix(filename, ext)) v.AddConfigPath(configPath) if err := v.ReadInConfig(); err != nil { return fmt.Errorf("Could not read config at :%s, viper error: %v", configFile, err) } return nil }
go
func ParseViper(v *viper.Viper, configFile string) error { filename := filepath.Base(configFile) ext := filepath.Ext(configFile) configPath := filepath.Dir(configFile) v.SetConfigType(strings.TrimPrefix(ext, ".")) v.SetConfigName(strings.TrimSuffix(filename, ext)) v.AddConfigPath(configPath) if err := v.ReadInConfig(); err != nil { return fmt.Errorf("Could not read config at :%s, viper error: %v", configFile, err) } return nil }
[ "func", "ParseViper", "(", "v", "*", "viper", ".", "Viper", ",", "configFile", "string", ")", "error", "{", "filename", ":=", "filepath", ".", "Base", "(", "configFile", ")", "\n", "ext", ":=", "filepath", ".", "Ext", "(", "configFile", ")", "\n", "con...
// ParseViper tries to parse out a Viper from a configuration file.
[ "ParseViper", "tries", "to", "parse", "out", "a", "Viper", "from", "a", "configuration", "file", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/configuration.go#L225-L238
train
theupdateframework/notary
tuf/data/root.go
isValidRootStructure
func isValidRootStructure(r Root) error { expectedType := TUFTypes[CanonicalRootRole] if r.Type != expectedType { return ErrInvalidMetadata{ role: CanonicalRootRole, msg: fmt.Sprintf("expected type %s, not %s", expectedType, r.Type)} } if r.Version < 1 { return ErrInvalidMetadata{ role: CanonicalRootRole, msg: "version cannot be less than 1"} } // all the base roles MUST appear in the root.json - other roles are allowed, // but other than the mirror role (not currently supported) are out of spec for _, roleName := range BaseRoles { roleObj, ok := r.Roles[roleName] if !ok || roleObj == nil { return ErrInvalidMetadata{ role: CanonicalRootRole, msg: fmt.Sprintf("missing %s role specification", roleName)} } if err := isValidRootRoleStructure(CanonicalRootRole, roleName, *roleObj, r.Keys); err != nil { return err } } return nil }
go
func isValidRootStructure(r Root) error { expectedType := TUFTypes[CanonicalRootRole] if r.Type != expectedType { return ErrInvalidMetadata{ role: CanonicalRootRole, msg: fmt.Sprintf("expected type %s, not %s", expectedType, r.Type)} } if r.Version < 1 { return ErrInvalidMetadata{ role: CanonicalRootRole, msg: "version cannot be less than 1"} } // all the base roles MUST appear in the root.json - other roles are allowed, // but other than the mirror role (not currently supported) are out of spec for _, roleName := range BaseRoles { roleObj, ok := r.Roles[roleName] if !ok || roleObj == nil { return ErrInvalidMetadata{ role: CanonicalRootRole, msg: fmt.Sprintf("missing %s role specification", roleName)} } if err := isValidRootRoleStructure(CanonicalRootRole, roleName, *roleObj, r.Keys); err != nil { return err } } return nil }
[ "func", "isValidRootStructure", "(", "r", "Root", ")", "error", "{", "expectedType", ":=", "TUFTypes", "[", "CanonicalRootRole", "]", "\n", "if", "r", ".", "Type", "!=", "expectedType", "{", "return", "ErrInvalidMetadata", "{", "role", ":", "CanonicalRootRole", ...
// isValidRootStructure returns an error, or nil, depending on whether the content of the struct // is valid for root metadata. This does not check signatures or expiry, just that // the metadata content is valid.
[ "isValidRootStructure", "returns", "an", "error", "or", "nil", "depending", "on", "whether", "the", "content", "of", "the", "struct", "is", "valid", "for", "root", "metadata", ".", "This", "does", "not", "check", "signatures", "or", "expiry", "just", "that", ...
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/root.go#L27-L52
train
theupdateframework/notary
tuf/data/root.go
NewRoot
func NewRoot(keys map[string]PublicKey, roles map[RoleName]*RootRole, consistent bool) (*SignedRoot, error) { signedRoot := &SignedRoot{ Signatures: make([]Signature, 0), Signed: Root{ SignedCommon: SignedCommon{ Type: TUFTypes[CanonicalRootRole], Version: 0, Expires: DefaultExpires(CanonicalRootRole), }, Keys: keys, Roles: roles, ConsistentSnapshot: consistent, }, Dirty: true, } return signedRoot, nil }
go
func NewRoot(keys map[string]PublicKey, roles map[RoleName]*RootRole, consistent bool) (*SignedRoot, error) { signedRoot := &SignedRoot{ Signatures: make([]Signature, 0), Signed: Root{ SignedCommon: SignedCommon{ Type: TUFTypes[CanonicalRootRole], Version: 0, Expires: DefaultExpires(CanonicalRootRole), }, Keys: keys, Roles: roles, ConsistentSnapshot: consistent, }, Dirty: true, } return signedRoot, nil }
[ "func", "NewRoot", "(", "keys", "map", "[", "string", "]", "PublicKey", ",", "roles", "map", "[", "RoleName", "]", "*", "RootRole", ",", "consistent", "bool", ")", "(", "*", "SignedRoot", ",", "error", ")", "{", "signedRoot", ":=", "&", "SignedRoot", "...
// NewRoot initializes a new SignedRoot with a set of keys, roles, and the consistent flag
[ "NewRoot", "initializes", "a", "new", "SignedRoot", "with", "a", "set", "of", "keys", "roles", "and", "the", "consistent", "flag" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/root.go#L73-L90
train
theupdateframework/notary
tuf/data/root.go
BuildBaseRole
func (r SignedRoot) BuildBaseRole(roleName RoleName) (BaseRole, error) { roleData, ok := r.Signed.Roles[roleName] if !ok { return BaseRole{}, ErrInvalidRole{Role: roleName, Reason: "role not found in root file"} } // Get all public keys for the base role from TUF metadata keyIDs := roleData.KeyIDs pubKeys := make(map[string]PublicKey) for _, keyID := range keyIDs { pubKey, ok := r.Signed.Keys[keyID] if !ok { return BaseRole{}, ErrInvalidRole{ Role: roleName, Reason: fmt.Sprintf("key with ID %s was not found in root metadata", keyID), } } pubKeys[keyID] = pubKey } return BaseRole{ Name: roleName, Keys: pubKeys, Threshold: roleData.Threshold, }, nil }
go
func (r SignedRoot) BuildBaseRole(roleName RoleName) (BaseRole, error) { roleData, ok := r.Signed.Roles[roleName] if !ok { return BaseRole{}, ErrInvalidRole{Role: roleName, Reason: "role not found in root file"} } // Get all public keys for the base role from TUF metadata keyIDs := roleData.KeyIDs pubKeys := make(map[string]PublicKey) for _, keyID := range keyIDs { pubKey, ok := r.Signed.Keys[keyID] if !ok { return BaseRole{}, ErrInvalidRole{ Role: roleName, Reason: fmt.Sprintf("key with ID %s was not found in root metadata", keyID), } } pubKeys[keyID] = pubKey } return BaseRole{ Name: roleName, Keys: pubKeys, Threshold: roleData.Threshold, }, nil }
[ "func", "(", "r", "SignedRoot", ")", "BuildBaseRole", "(", "roleName", "RoleName", ")", "(", "BaseRole", ",", "error", ")", "{", "roleData", ",", "ok", ":=", "r", ".", "Signed", ".", "Roles", "[", "roleName", "]", "\n", "if", "!", "ok", "{", "return"...
// BuildBaseRole returns a copy of a BaseRole using the information in this SignedRoot for the specified role name. // Will error for invalid role name or key metadata within this SignedRoot
[ "BuildBaseRole", "returns", "a", "copy", "of", "a", "BaseRole", "using", "the", "information", "in", "this", "SignedRoot", "for", "the", "specified", "role", "name", ".", "Will", "error", "for", "invalid", "role", "name", "or", "key", "metadata", "within", "...
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/root.go#L94-L118
train
theupdateframework/notary
tuf/data/root.go
MarshalJSON
func (r SignedRoot) MarshalJSON() ([]byte, error) { signed, err := r.ToSigned() if err != nil { return nil, err } return defaultSerializer.Marshal(signed) }
go
func (r SignedRoot) MarshalJSON() ([]byte, error) { signed, err := r.ToSigned() if err != nil { return nil, err } return defaultSerializer.Marshal(signed) }
[ "func", "(", "r", "SignedRoot", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "signed", ",", "err", ":=", "r", ".", "ToSigned", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}"...
// MarshalJSON returns the serialized form of SignedRoot as bytes
[ "MarshalJSON", "returns", "the", "serialized", "form", "of", "SignedRoot", "as", "bytes" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/root.go#L141-L147
train
theupdateframework/notary
tuf/data/root.go
RootFromSigned
func RootFromSigned(s *Signed) (*SignedRoot, error) { r := Root{} if s.Signed == nil { return nil, ErrInvalidMetadata{ role: CanonicalRootRole, msg: "root file contained an empty payload", } } if err := defaultSerializer.Unmarshal(*s.Signed, &r); err != nil { return nil, err } if err := isValidRootStructure(r); err != nil { return nil, err } sigs := make([]Signature, len(s.Signatures)) copy(sigs, s.Signatures) return &SignedRoot{ Signatures: sigs, Signed: r, }, nil }
go
func RootFromSigned(s *Signed) (*SignedRoot, error) { r := Root{} if s.Signed == nil { return nil, ErrInvalidMetadata{ role: CanonicalRootRole, msg: "root file contained an empty payload", } } if err := defaultSerializer.Unmarshal(*s.Signed, &r); err != nil { return nil, err } if err := isValidRootStructure(r); err != nil { return nil, err } sigs := make([]Signature, len(s.Signatures)) copy(sigs, s.Signatures) return &SignedRoot{ Signatures: sigs, Signed: r, }, nil }
[ "func", "RootFromSigned", "(", "s", "*", "Signed", ")", "(", "*", "SignedRoot", ",", "error", ")", "{", "r", ":=", "Root", "{", "}", "\n", "if", "s", ".", "Signed", "==", "nil", "{", "return", "nil", ",", "ErrInvalidMetadata", "{", "role", ":", "Ca...
// RootFromSigned fully unpacks a Signed object into a SignedRoot and ensures // that it is a valid SignedRoot
[ "RootFromSigned", "fully", "unpacks", "a", "Signed", "object", "into", "a", "SignedRoot", "and", "ensures", "that", "it", "is", "a", "valid", "SignedRoot" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/root.go#L151-L171
train
theupdateframework/notary
signer/api/find_key.go
findKeyByID
func findKeyByID(cryptoServices signer.CryptoServiceIndex, keyID *pb.KeyID) (data.PrivateKey, data.RoleName, error) { for _, service := range cryptoServices { key, role, err := service.GetPrivateKey(keyID.ID) if err == nil { return key, role, nil } } return nil, "", trustmanager.ErrKeyNotFound{KeyID: keyID.ID} }
go
func findKeyByID(cryptoServices signer.CryptoServiceIndex, keyID *pb.KeyID) (data.PrivateKey, data.RoleName, error) { for _, service := range cryptoServices { key, role, err := service.GetPrivateKey(keyID.ID) if err == nil { return key, role, nil } } return nil, "", trustmanager.ErrKeyNotFound{KeyID: keyID.ID} }
[ "func", "findKeyByID", "(", "cryptoServices", "signer", ".", "CryptoServiceIndex", ",", "keyID", "*", "pb", ".", "KeyID", ")", "(", "data", ".", "PrivateKey", ",", "data", ".", "RoleName", ",", "error", ")", "{", "for", "_", ",", "service", ":=", "range"...
// findKeyByID looks for the key with the given ID in each of the // signing services in sigServices. It returns the first matching key it finds, // or ErrInvalidKeyID if the key is not found in any of the signing services.
[ "findKeyByID", "looks", "for", "the", "key", "with", "the", "given", "ID", "in", "each", "of", "the", "signing", "services", "in", "sigServices", ".", "It", "returns", "the", "first", "matching", "key", "it", "finds", "or", "ErrInvalidKeyID", "if", "the", ...
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/signer/api/find_key.go#L14-L23
train
theupdateframework/notary
tuf/data/snapshot.go
IsValidSnapshotStructure
func IsValidSnapshotStructure(s Snapshot) error { expectedType := TUFTypes[CanonicalSnapshotRole] if s.Type != expectedType { return ErrInvalidMetadata{ role: CanonicalSnapshotRole, msg: fmt.Sprintf("expected type %s, not %s", expectedType, s.Type)} } if s.Version < 1 { return ErrInvalidMetadata{ role: CanonicalSnapshotRole, msg: "version cannot be less than one"} } for _, file := range []RoleName{CanonicalRootRole, CanonicalTargetsRole} { // Meta is a map of FileMeta, so if the role isn't in the map it returns // an empty FileMeta, which has an empty map, and you can check on keys // from an empty map. // // For now sha256 is required and sha512 is not. if _, ok := s.Meta[file.String()].Hashes[notary.SHA256]; !ok { return ErrInvalidMetadata{ role: CanonicalSnapshotRole, msg: fmt.Sprintf("missing %s sha256 checksum information", file.String()), } } if err := CheckValidHashStructures(s.Meta[file.String()].Hashes); err != nil { return ErrInvalidMetadata{ role: CanonicalSnapshotRole, msg: fmt.Sprintf("invalid %s checksum information, %v", file.String(), err), } } } return nil }
go
func IsValidSnapshotStructure(s Snapshot) error { expectedType := TUFTypes[CanonicalSnapshotRole] if s.Type != expectedType { return ErrInvalidMetadata{ role: CanonicalSnapshotRole, msg: fmt.Sprintf("expected type %s, not %s", expectedType, s.Type)} } if s.Version < 1 { return ErrInvalidMetadata{ role: CanonicalSnapshotRole, msg: "version cannot be less than one"} } for _, file := range []RoleName{CanonicalRootRole, CanonicalTargetsRole} { // Meta is a map of FileMeta, so if the role isn't in the map it returns // an empty FileMeta, which has an empty map, and you can check on keys // from an empty map. // // For now sha256 is required and sha512 is not. if _, ok := s.Meta[file.String()].Hashes[notary.SHA256]; !ok { return ErrInvalidMetadata{ role: CanonicalSnapshotRole, msg: fmt.Sprintf("missing %s sha256 checksum information", file.String()), } } if err := CheckValidHashStructures(s.Meta[file.String()].Hashes); err != nil { return ErrInvalidMetadata{ role: CanonicalSnapshotRole, msg: fmt.Sprintf("invalid %s checksum information, %v", file.String(), err), } } } return nil }
[ "func", "IsValidSnapshotStructure", "(", "s", "Snapshot", ")", "error", "{", "expectedType", ":=", "TUFTypes", "[", "CanonicalSnapshotRole", "]", "\n", "if", "s", ".", "Type", "!=", "expectedType", "{", "return", "ErrInvalidMetadata", "{", "role", ":", "Canonica...
// IsValidSnapshotStructure returns an error, or nil, depending on whether the content of the // struct is valid for snapshot metadata. This does not check signatures or expiry, just that // the metadata content is valid.
[ "IsValidSnapshotStructure", "returns", "an", "error", "or", "nil", "depending", "on", "whether", "the", "content", "of", "the", "struct", "is", "valid", "for", "snapshot", "metadata", ".", "This", "does", "not", "check", "signatures", "or", "expiry", "just", "...
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/snapshot.go#L28-L60
train
theupdateframework/notary
tuf/data/snapshot.go
NewSnapshot
func NewSnapshot(root *Signed, targets *Signed) (*SignedSnapshot, error) { logrus.Debug("generating new snapshot...") targetsJSON, err := json.Marshal(targets) if err != nil { logrus.Debug("Error Marshalling Targets") return nil, err } rootJSON, err := json.Marshal(root) if err != nil { logrus.Debug("Error Marshalling Root") return nil, err } rootMeta, err := NewFileMeta(bytes.NewReader(rootJSON), NotaryDefaultHashes...) if err != nil { return nil, err } targetsMeta, err := NewFileMeta(bytes.NewReader(targetsJSON), NotaryDefaultHashes...) if err != nil { return nil, err } return &SignedSnapshot{ Signatures: make([]Signature, 0), Signed: Snapshot{ SignedCommon: SignedCommon{ Type: TUFTypes[CanonicalSnapshotRole], Version: 0, Expires: DefaultExpires(CanonicalSnapshotRole), }, Meta: Files{ CanonicalRootRole.String(): rootMeta, CanonicalTargetsRole.String(): targetsMeta, }, }, }, nil }
go
func NewSnapshot(root *Signed, targets *Signed) (*SignedSnapshot, error) { logrus.Debug("generating new snapshot...") targetsJSON, err := json.Marshal(targets) if err != nil { logrus.Debug("Error Marshalling Targets") return nil, err } rootJSON, err := json.Marshal(root) if err != nil { logrus.Debug("Error Marshalling Root") return nil, err } rootMeta, err := NewFileMeta(bytes.NewReader(rootJSON), NotaryDefaultHashes...) if err != nil { return nil, err } targetsMeta, err := NewFileMeta(bytes.NewReader(targetsJSON), NotaryDefaultHashes...) if err != nil { return nil, err } return &SignedSnapshot{ Signatures: make([]Signature, 0), Signed: Snapshot{ SignedCommon: SignedCommon{ Type: TUFTypes[CanonicalSnapshotRole], Version: 0, Expires: DefaultExpires(CanonicalSnapshotRole), }, Meta: Files{ CanonicalRootRole.String(): rootMeta, CanonicalTargetsRole.String(): targetsMeta, }, }, }, nil }
[ "func", "NewSnapshot", "(", "root", "*", "Signed", ",", "targets", "*", "Signed", ")", "(", "*", "SignedSnapshot", ",", "error", ")", "{", "logrus", ".", "Debug", "(", "\"generating new snapshot...\"", ")", "\n", "targetsJSON", ",", "err", ":=", "json", "....
// NewSnapshot initializes a SignedSnapshot with a given top level root // and targets objects
[ "NewSnapshot", "initializes", "a", "SignedSnapshot", "with", "a", "given", "top", "level", "root", "and", "targets", "objects" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/snapshot.go#L64-L98
train
theupdateframework/notary
tuf/data/snapshot.go
AddMeta
func (sp *SignedSnapshot) AddMeta(role RoleName, meta FileMeta) { sp.Signed.Meta[role.String()] = meta sp.Dirty = true }
go
func (sp *SignedSnapshot) AddMeta(role RoleName, meta FileMeta) { sp.Signed.Meta[role.String()] = meta sp.Dirty = true }
[ "func", "(", "sp", "*", "SignedSnapshot", ")", "AddMeta", "(", "role", "RoleName", ",", "meta", "FileMeta", ")", "{", "sp", ".", "Signed", ".", "Meta", "[", "role", ".", "String", "(", ")", "]", "=", "meta", "\n", "sp", ".", "Dirty", "=", "true", ...
// AddMeta updates a role in the snapshot with new meta
[ "AddMeta", "updates", "a", "role", "in", "the", "snapshot", "with", "new", "meta" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/snapshot.go#L120-L123
train
theupdateframework/notary
tuf/data/snapshot.go
GetMeta
func (sp *SignedSnapshot) GetMeta(role RoleName) (*FileMeta, error) { if meta, ok := sp.Signed.Meta[role.String()]; ok { if _, ok := meta.Hashes["sha256"]; ok { return &meta, nil } } return nil, ErrMissingMeta{Role: role.String()} }
go
func (sp *SignedSnapshot) GetMeta(role RoleName) (*FileMeta, error) { if meta, ok := sp.Signed.Meta[role.String()]; ok { if _, ok := meta.Hashes["sha256"]; ok { return &meta, nil } } return nil, ErrMissingMeta{Role: role.String()} }
[ "func", "(", "sp", "*", "SignedSnapshot", ")", "GetMeta", "(", "role", "RoleName", ")", "(", "*", "FileMeta", ",", "error", ")", "{", "if", "meta", ",", "ok", ":=", "sp", ".", "Signed", ".", "Meta", "[", "role", ".", "String", "(", ")", "]", ";",...
// GetMeta gets the metadata for a particular role, returning an error if it's // not found
[ "GetMeta", "gets", "the", "metadata", "for", "a", "particular", "role", "returning", "an", "error", "if", "it", "s", "not", "found" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/snapshot.go#L127-L134
train
theupdateframework/notary
tuf/data/snapshot.go
DeleteMeta
func (sp *SignedSnapshot) DeleteMeta(role RoleName) { if _, ok := sp.Signed.Meta[role.String()]; ok { delete(sp.Signed.Meta, role.String()) sp.Dirty = true } }
go
func (sp *SignedSnapshot) DeleteMeta(role RoleName) { if _, ok := sp.Signed.Meta[role.String()]; ok { delete(sp.Signed.Meta, role.String()) sp.Dirty = true } }
[ "func", "(", "sp", "*", "SignedSnapshot", ")", "DeleteMeta", "(", "role", "RoleName", ")", "{", "if", "_", ",", "ok", ":=", "sp", ".", "Signed", ".", "Meta", "[", "role", ".", "String", "(", ")", "]", ";", "ok", "{", "delete", "(", "sp", ".", "...
// DeleteMeta removes a role from the snapshot. If the role doesn't // exist in the snapshot, it's a noop.
[ "DeleteMeta", "removes", "a", "role", "from", "the", "snapshot", ".", "If", "the", "role", "doesn", "t", "exist", "in", "the", "snapshot", "it", "s", "a", "noop", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/snapshot.go#L138-L143
train
theupdateframework/notary
tuf/data/snapshot.go
MarshalJSON
func (sp *SignedSnapshot) MarshalJSON() ([]byte, error) { signed, err := sp.ToSigned() if err != nil { return nil, err } return defaultSerializer.Marshal(signed) }
go
func (sp *SignedSnapshot) MarshalJSON() ([]byte, error) { signed, err := sp.ToSigned() if err != nil { return nil, err } return defaultSerializer.Marshal(signed) }
[ "func", "(", "sp", "*", "SignedSnapshot", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "signed", ",", "err", ":=", "sp", ".", "ToSigned", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", ...
// MarshalJSON returns the serialized form of SignedSnapshot as bytes
[ "MarshalJSON", "returns", "the", "serialized", "form", "of", "SignedSnapshot", "as", "bytes" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/snapshot.go#L146-L152
train
theupdateframework/notary
tuf/data/snapshot.go
SnapshotFromSigned
func SnapshotFromSigned(s *Signed) (*SignedSnapshot, error) { sp := Snapshot{} if err := defaultSerializer.Unmarshal(*s.Signed, &sp); err != nil { return nil, err } if err := IsValidSnapshotStructure(sp); err != nil { return nil, err } sigs := make([]Signature, len(s.Signatures)) copy(sigs, s.Signatures) return &SignedSnapshot{ Signatures: sigs, Signed: sp, }, nil }
go
func SnapshotFromSigned(s *Signed) (*SignedSnapshot, error) { sp := Snapshot{} if err := defaultSerializer.Unmarshal(*s.Signed, &sp); err != nil { return nil, err } if err := IsValidSnapshotStructure(sp); err != nil { return nil, err } sigs := make([]Signature, len(s.Signatures)) copy(sigs, s.Signatures) return &SignedSnapshot{ Signatures: sigs, Signed: sp, }, nil }
[ "func", "SnapshotFromSigned", "(", "s", "*", "Signed", ")", "(", "*", "SignedSnapshot", ",", "error", ")", "{", "sp", ":=", "Snapshot", "{", "}", "\n", "if", "err", ":=", "defaultSerializer", ".", "Unmarshal", "(", "*", "s", ".", "Signed", ",", "&", ...
// SnapshotFromSigned fully unpacks a Signed object into a SignedSnapshot
[ "SnapshotFromSigned", "fully", "unpacks", "a", "Signed", "object", "into", "a", "SignedSnapshot" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/snapshot.go#L155-L169
train
theupdateframework/notary
tuf/data/roles.go
ValidRole
func ValidRole(name RoleName) bool { if IsDelegation(name) { return true } for _, v := range BaseRoles { if name == v { return true } } return false }
go
func ValidRole(name RoleName) bool { if IsDelegation(name) { return true } for _, v := range BaseRoles { if name == v { return true } } return false }
[ "func", "ValidRole", "(", "name", "RoleName", ")", "bool", "{", "if", "IsDelegation", "(", "name", ")", "{", "return", "true", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "BaseRoles", "{", "if", "name", "==", "v", "{", "return", "true", "...
// ValidRole only determines the name is semantically // correct. For target delegated roles, it does NOT check // the the appropriate parent roles exist.
[ "ValidRole", "only", "determines", "the", "name", "is", "semantically", "correct", ".", "For", "target", "delegated", "roles", "it", "does", "NOT", "check", "the", "the", "appropriate", "parent", "roles", "exist", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L59-L70
train
theupdateframework/notary
tuf/data/roles.go
IsDelegation
func IsDelegation(role RoleName) bool { strRole := role.String() targetsBase := CanonicalTargetsRole + "/" whitelistedChars := delegationRegexp.MatchString(strRole) // Limit size of full role string to 255 chars for db column size limit correctLength := len(role) < 256 // Removes ., .., extra slashes, and trailing slash isClean := path.Clean(strRole) == strRole return strings.HasPrefix(strRole, targetsBase.String()) && whitelistedChars && correctLength && isClean }
go
func IsDelegation(role RoleName) bool { strRole := role.String() targetsBase := CanonicalTargetsRole + "/" whitelistedChars := delegationRegexp.MatchString(strRole) // Limit size of full role string to 255 chars for db column size limit correctLength := len(role) < 256 // Removes ., .., extra slashes, and trailing slash isClean := path.Clean(strRole) == strRole return strings.HasPrefix(strRole, targetsBase.String()) && whitelistedChars && correctLength && isClean }
[ "func", "IsDelegation", "(", "role", "RoleName", ")", "bool", "{", "strRole", ":=", "role", ".", "String", "(", ")", "\n", "targetsBase", ":=", "CanonicalTargetsRole", "+", "\"/\"", "\n", "whitelistedChars", ":=", "delegationRegexp", ".", "MatchString", "(", "...
// IsDelegation checks if the role is a delegation or a root role
[ "IsDelegation", "checks", "if", "the", "role", "is", "a", "delegation", "or", "a", "root", "role" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L73-L88
train
theupdateframework/notary
tuf/data/roles.go
IsBaseRole
func IsBaseRole(role RoleName) bool { for _, baseRole := range BaseRoles { if role == baseRole { return true } } return false }
go
func IsBaseRole(role RoleName) bool { for _, baseRole := range BaseRoles { if role == baseRole { return true } } return false }
[ "func", "IsBaseRole", "(", "role", "RoleName", ")", "bool", "{", "for", "_", ",", "baseRole", ":=", "range", "BaseRoles", "{", "if", "role", "==", "baseRole", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsBaseRole checks if the role is a base role
[ "IsBaseRole", "checks", "if", "the", "role", "is", "a", "base", "role" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L91-L98
train
theupdateframework/notary
tuf/data/roles.go
NewBaseRole
func NewBaseRole(name RoleName, threshold int, keys ...PublicKey) BaseRole { r := BaseRole{ Name: name, Threshold: threshold, Keys: make(map[string]PublicKey), } for _, k := range keys { r.Keys[k.ID()] = k } return r }
go
func NewBaseRole(name RoleName, threshold int, keys ...PublicKey) BaseRole { r := BaseRole{ Name: name, Threshold: threshold, Keys: make(map[string]PublicKey), } for _, k := range keys { r.Keys[k.ID()] = k } return r }
[ "func", "NewBaseRole", "(", "name", "RoleName", ",", "threshold", "int", ",", "keys", "...", "PublicKey", ")", "BaseRole", "{", "r", ":=", "BaseRole", "{", "Name", ":", "name", ",", "Threshold", ":", "threshold", ",", "Keys", ":", "make", "(", "map", "...
// NewBaseRole creates a new BaseRole object with the provided parameters
[ "NewBaseRole", "creates", "a", "new", "BaseRole", "object", "with", "the", "provided", "parameters" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L123-L133
train
theupdateframework/notary
tuf/data/roles.go
Equals
func (b BaseRole) Equals(o BaseRole) bool { if b.Threshold != o.Threshold || b.Name != o.Name || len(b.Keys) != len(o.Keys) { return false } for keyID, key := range b.Keys { oKey, ok := o.Keys[keyID] if !ok || key.ID() != oKey.ID() { return false } } return true }
go
func (b BaseRole) Equals(o BaseRole) bool { if b.Threshold != o.Threshold || b.Name != o.Name || len(b.Keys) != len(o.Keys) { return false } for keyID, key := range b.Keys { oKey, ok := o.Keys[keyID] if !ok || key.ID() != oKey.ID() { return false } } return true }
[ "func", "(", "b", "BaseRole", ")", "Equals", "(", "o", "BaseRole", ")", "bool", "{", "if", "b", ".", "Threshold", "!=", "o", ".", "Threshold", "||", "b", ".", "Name", "!=", "o", ".", "Name", "||", "len", "(", "b", ".", "Keys", ")", "!=", "len",...
// Equals returns whether this BaseRole equals another BaseRole
[ "Equals", "returns", "whether", "this", "BaseRole", "equals", "another", "BaseRole" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L146-L159
train
theupdateframework/notary
tuf/data/roles.go
Restrict
func (d DelegationRole) Restrict(child DelegationRole) (DelegationRole, error) { if !d.IsParentOf(child) { return DelegationRole{}, fmt.Errorf("%s is not a parent of %s", d.Name, child.Name) } return DelegationRole{ BaseRole: BaseRole{ Keys: child.Keys, Name: child.Name, Threshold: child.Threshold, }, Paths: RestrictDelegationPathPrefixes(d.Paths, child.Paths), }, nil }
go
func (d DelegationRole) Restrict(child DelegationRole) (DelegationRole, error) { if !d.IsParentOf(child) { return DelegationRole{}, fmt.Errorf("%s is not a parent of %s", d.Name, child.Name) } return DelegationRole{ BaseRole: BaseRole{ Keys: child.Keys, Name: child.Name, Threshold: child.Threshold, }, Paths: RestrictDelegationPathPrefixes(d.Paths, child.Paths), }, nil }
[ "func", "(", "d", "DelegationRole", ")", "Restrict", "(", "child", "DelegationRole", ")", "(", "DelegationRole", ",", "error", ")", "{", "if", "!", "d", ".", "IsParentOf", "(", "child", ")", "{", "return", "DelegationRole", "{", "}", ",", "fmt", ".", "...
// Restrict restricts the paths and path hash prefixes for the passed in delegation role, // returning a copy of the role with validated paths as if it was a direct child
[ "Restrict", "restricts", "the", "paths", "and", "path", "hash", "prefixes", "for", "the", "passed", "in", "delegation", "role", "returning", "a", "copy", "of", "the", "role", "with", "validated", "paths", "as", "if", "it", "was", "a", "direct", "child" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L185-L197
train
theupdateframework/notary
tuf/data/roles.go
RestrictDelegationPathPrefixes
func RestrictDelegationPathPrefixes(parentPaths, delegationPaths []string) []string { validPaths := []string{} if len(delegationPaths) == 0 { return validPaths } // Validate each individual delegation path for _, delgPath := range delegationPaths { isPrefixed := false for _, parentPath := range parentPaths { if strings.HasPrefix(delgPath, parentPath) { isPrefixed = true break } } // If the delegation path did not match prefix against any parent path, it is not valid if isPrefixed { validPaths = append(validPaths, delgPath) } } return validPaths }
go
func RestrictDelegationPathPrefixes(parentPaths, delegationPaths []string) []string { validPaths := []string{} if len(delegationPaths) == 0 { return validPaths } // Validate each individual delegation path for _, delgPath := range delegationPaths { isPrefixed := false for _, parentPath := range parentPaths { if strings.HasPrefix(delgPath, parentPath) { isPrefixed = true break } } // If the delegation path did not match prefix against any parent path, it is not valid if isPrefixed { validPaths = append(validPaths, delgPath) } } return validPaths }
[ "func", "RestrictDelegationPathPrefixes", "(", "parentPaths", ",", "delegationPaths", "[", "]", "string", ")", "[", "]", "string", "{", "validPaths", ":=", "[", "]", "string", "{", "}", "\n", "if", "len", "(", "delegationPaths", ")", "==", "0", "{", "retur...
// RestrictDelegationPathPrefixes returns the list of valid delegationPaths that are prefixed by parentPaths
[ "RestrictDelegationPathPrefixes", "returns", "the", "list", "of", "valid", "delegationPaths", "that", "are", "prefixed", "by", "parentPaths" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L221-L242
train
theupdateframework/notary
tuf/data/roles.go
NewRole
func NewRole(name RoleName, threshold int, keyIDs, paths []string) (*Role, error) { if IsDelegation(name) { if len(paths) == 0 { logrus.Debugf("role %s with no Paths will never be able to publish content until one or more are added", name) } } if threshold < 1 { return nil, ErrInvalidRole{Role: name} } if !ValidRole(name) { return nil, ErrInvalidRole{Role: name} } return &Role{ RootRole: RootRole{ KeyIDs: keyIDs, Threshold: threshold, }, Name: name, Paths: paths, }, nil }
go
func NewRole(name RoleName, threshold int, keyIDs, paths []string) (*Role, error) { if IsDelegation(name) { if len(paths) == 0 { logrus.Debugf("role %s with no Paths will never be able to publish content until one or more are added", name) } } if threshold < 1 { return nil, ErrInvalidRole{Role: name} } if !ValidRole(name) { return nil, ErrInvalidRole{Role: name} } return &Role{ RootRole: RootRole{ KeyIDs: keyIDs, Threshold: threshold, }, Name: name, Paths: paths, }, nil }
[ "func", "NewRole", "(", "name", "RoleName", ",", "threshold", "int", ",", "keyIDs", ",", "paths", "[", "]", "string", ")", "(", "*", "Role", ",", "error", ")", "{", "if", "IsDelegation", "(", "name", ")", "{", "if", "len", "(", "paths", ")", "==", ...
// NewRole creates a new Role object from the given parameters
[ "NewRole", "creates", "a", "new", "Role", "object", "from", "the", "given", "parameters" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L260-L281
train
theupdateframework/notary
tuf/data/roles.go
AddKeys
func (r *Role) AddKeys(ids []string) { r.KeyIDs = mergeStrSlices(r.KeyIDs, ids) }
go
func (r *Role) AddKeys(ids []string) { r.KeyIDs = mergeStrSlices(r.KeyIDs, ids) }
[ "func", "(", "r", "*", "Role", ")", "AddKeys", "(", "ids", "[", "]", "string", ")", "{", "r", ".", "KeyIDs", "=", "mergeStrSlices", "(", "r", ".", "KeyIDs", ",", "ids", ")", "\n", "}" ]
// AddKeys merges the ids into the current list of role key ids
[ "AddKeys", "merges", "the", "ids", "into", "the", "current", "list", "of", "role", "key", "ids" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L289-L291
train
theupdateframework/notary
tuf/data/roles.go
AddPaths
func (r *Role) AddPaths(paths []string) error { if len(paths) == 0 { return nil } r.Paths = mergeStrSlices(r.Paths, paths) return nil }
go
func (r *Role) AddPaths(paths []string) error { if len(paths) == 0 { return nil } r.Paths = mergeStrSlices(r.Paths, paths) return nil }
[ "func", "(", "r", "*", "Role", ")", "AddPaths", "(", "paths", "[", "]", "string", ")", "error", "{", "if", "len", "(", "paths", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "r", ".", "Paths", "=", "mergeStrSlices", "(", "r", ".", "Pat...
// AddPaths merges the paths into the current list of role paths
[ "AddPaths", "merges", "the", "paths", "into", "the", "current", "list", "of", "role", "paths" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L294-L300
train
theupdateframework/notary
tuf/data/roles.go
RemoveKeys
func (r *Role) RemoveKeys(ids []string) { r.KeyIDs = subtractStrSlices(r.KeyIDs, ids) }
go
func (r *Role) RemoveKeys(ids []string) { r.KeyIDs = subtractStrSlices(r.KeyIDs, ids) }
[ "func", "(", "r", "*", "Role", ")", "RemoveKeys", "(", "ids", "[", "]", "string", ")", "{", "r", ".", "KeyIDs", "=", "subtractStrSlices", "(", "r", ".", "KeyIDs", ",", "ids", ")", "\n", "}" ]
// RemoveKeys removes the ids from the current list of key ids
[ "RemoveKeys", "removes", "the", "ids", "from", "the", "current", "list", "of", "key", "ids" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L303-L305
train
theupdateframework/notary
tuf/data/roles.go
RemovePaths
func (r *Role) RemovePaths(paths []string) { r.Paths = subtractStrSlices(r.Paths, paths) }
go
func (r *Role) RemovePaths(paths []string) { r.Paths = subtractStrSlices(r.Paths, paths) }
[ "func", "(", "r", "*", "Role", ")", "RemovePaths", "(", "paths", "[", "]", "string", ")", "{", "r", ".", "Paths", "=", "subtractStrSlices", "(", "r", ".", "Paths", ",", "paths", ")", "\n", "}" ]
// RemovePaths removes the paths from the current list of role paths
[ "RemovePaths", "removes", "the", "paths", "from", "the", "current", "list", "of", "role", "paths" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/roles.go#L308-L310
train
theupdateframework/notary
server/storage/memory.go
NewMemStorage
func NewMemStorage() *MemStorage { return &MemStorage{ tufMeta: make(map[string]verList), keys: make(map[string]map[string]*key), checksums: make(map[string]map[string]ver), } }
go
func NewMemStorage() *MemStorage { return &MemStorage{ tufMeta: make(map[string]verList), keys: make(map[string]map[string]*key), checksums: make(map[string]map[string]ver), } }
[ "func", "NewMemStorage", "(", ")", "*", "MemStorage", "{", "return", "&", "MemStorage", "{", "tufMeta", ":", "make", "(", "map", "[", "string", "]", "verList", ")", ",", "keys", ":", "make", "(", "map", "[", "string", "]", "map", "[", "string", "]", ...
// NewMemStorage instantiates a memStorage instance
[ "NewMemStorage", "instantiates", "a", "memStorage", "instance" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/memory.go#L48-L54
train
theupdateframework/notary
server/storage/memory.go
UpdateCurrent
func (st *MemStorage) UpdateCurrent(gun data.GUN, update MetaUpdate) error { id := entryKey(gun, update.Role) st.lock.Lock() defer st.lock.Unlock() if space, ok := st.tufMeta[id]; ok { for _, v := range space { if v.version >= update.Version { return ErrOldVersion{} } } } version := ver{version: update.Version, data: update.Data, createupdate: time.Now()} st.tufMeta[id] = append(st.tufMeta[id], version) checksumBytes := sha256.Sum256(update.Data) checksum := hex.EncodeToString(checksumBytes[:]) _, ok := st.checksums[gun.String()] if !ok { st.checksums[gun.String()] = make(map[string]ver) } st.checksums[gun.String()][checksum] = version if update.Role == data.CanonicalTimestampRole { st.writeChange(gun, update.Version, checksum) } return nil }
go
func (st *MemStorage) UpdateCurrent(gun data.GUN, update MetaUpdate) error { id := entryKey(gun, update.Role) st.lock.Lock() defer st.lock.Unlock() if space, ok := st.tufMeta[id]; ok { for _, v := range space { if v.version >= update.Version { return ErrOldVersion{} } } } version := ver{version: update.Version, data: update.Data, createupdate: time.Now()} st.tufMeta[id] = append(st.tufMeta[id], version) checksumBytes := sha256.Sum256(update.Data) checksum := hex.EncodeToString(checksumBytes[:]) _, ok := st.checksums[gun.String()] if !ok { st.checksums[gun.String()] = make(map[string]ver) } st.checksums[gun.String()][checksum] = version if update.Role == data.CanonicalTimestampRole { st.writeChange(gun, update.Version, checksum) } return nil }
[ "func", "(", "st", "*", "MemStorage", ")", "UpdateCurrent", "(", "gun", "data", ".", "GUN", ",", "update", "MetaUpdate", ")", "error", "{", "id", ":=", "entryKey", "(", "gun", ",", "update", ".", "Role", ")", "\n", "st", ".", "lock", ".", "Lock", "...
// UpdateCurrent updates the meta data for a specific role
[ "UpdateCurrent", "updates", "the", "meta", "data", "for", "a", "specific", "role" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/memory.go#L57-L82
train
theupdateframework/notary
server/storage/memory.go
writeChange
func (st *MemStorage) writeChange(gun data.GUN, version int, checksum string) { c := Change{ ID: strconv.Itoa(len(st.changes) + 1), GUN: gun.String(), Version: version, SHA256: checksum, CreatedAt: time.Now(), Category: changeCategoryUpdate, } st.changes = append(st.changes, c) }
go
func (st *MemStorage) writeChange(gun data.GUN, version int, checksum string) { c := Change{ ID: strconv.Itoa(len(st.changes) + 1), GUN: gun.String(), Version: version, SHA256: checksum, CreatedAt: time.Now(), Category: changeCategoryUpdate, } st.changes = append(st.changes, c) }
[ "func", "(", "st", "*", "MemStorage", ")", "writeChange", "(", "gun", "data", ".", "GUN", ",", "version", "int", ",", "checksum", "string", ")", "{", "c", ":=", "Change", "{", "ID", ":", "strconv", ".", "Itoa", "(", "len", "(", "st", ".", "changes"...
// writeChange must only be called by a function already holding a lock on // the MemStorage. Behaviour is undefined otherwise
[ "writeChange", "must", "only", "be", "called", "by", "a", "function", "already", "holding", "a", "lock", "on", "the", "MemStorage", ".", "Behaviour", "is", "undefined", "otherwise" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/memory.go#L86-L96
train
theupdateframework/notary
server/storage/memory.go
UpdateMany
func (st *MemStorage) UpdateMany(gun data.GUN, updates []MetaUpdate) error { st.lock.Lock() defer st.lock.Unlock() versioner := make(map[string]map[int]struct{}) constant := struct{}{} // ensure that we only update in one transaction for _, u := range updates { id := entryKey(gun, u.Role) // prevent duplicate versions of the same role if _, ok := versioner[u.Role.String()][u.Version]; ok { return ErrOldVersion{} } if _, ok := versioner[u.Role.String()]; !ok { versioner[u.Role.String()] = make(map[int]struct{}) } versioner[u.Role.String()][u.Version] = constant if space, ok := st.tufMeta[id]; ok { for _, v := range space { if v.version >= u.Version { return ErrOldVersion{} } } } } for _, u := range updates { id := entryKey(gun, u.Role) version := ver{version: u.Version, data: u.Data, createupdate: time.Now()} st.tufMeta[id] = append(st.tufMeta[id], version) sort.Sort(st.tufMeta[id]) // ensure that it's sorted checksumBytes := sha256.Sum256(u.Data) checksum := hex.EncodeToString(checksumBytes[:]) _, ok := st.checksums[gun.String()] if !ok { st.checksums[gun.String()] = make(map[string]ver) } st.checksums[gun.String()][checksum] = version if u.Role == data.CanonicalTimestampRole { st.writeChange(gun, u.Version, checksum) } } return nil }
go
func (st *MemStorage) UpdateMany(gun data.GUN, updates []MetaUpdate) error { st.lock.Lock() defer st.lock.Unlock() versioner := make(map[string]map[int]struct{}) constant := struct{}{} // ensure that we only update in one transaction for _, u := range updates { id := entryKey(gun, u.Role) // prevent duplicate versions of the same role if _, ok := versioner[u.Role.String()][u.Version]; ok { return ErrOldVersion{} } if _, ok := versioner[u.Role.String()]; !ok { versioner[u.Role.String()] = make(map[int]struct{}) } versioner[u.Role.String()][u.Version] = constant if space, ok := st.tufMeta[id]; ok { for _, v := range space { if v.version >= u.Version { return ErrOldVersion{} } } } } for _, u := range updates { id := entryKey(gun, u.Role) version := ver{version: u.Version, data: u.Data, createupdate: time.Now()} st.tufMeta[id] = append(st.tufMeta[id], version) sort.Sort(st.tufMeta[id]) // ensure that it's sorted checksumBytes := sha256.Sum256(u.Data) checksum := hex.EncodeToString(checksumBytes[:]) _, ok := st.checksums[gun.String()] if !ok { st.checksums[gun.String()] = make(map[string]ver) } st.checksums[gun.String()][checksum] = version if u.Role == data.CanonicalTimestampRole { st.writeChange(gun, u.Version, checksum) } } return nil }
[ "func", "(", "st", "*", "MemStorage", ")", "UpdateMany", "(", "gun", "data", ".", "GUN", ",", "updates", "[", "]", "MetaUpdate", ")", "error", "{", "st", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "st", ".", "lock", ".", "Unlock", "(", ")...
// UpdateMany updates multiple TUF records
[ "UpdateMany", "updates", "multiple", "TUF", "records" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/memory.go#L99-L147
train
theupdateframework/notary
server/storage/memory.go
GetCurrent
func (st *MemStorage) GetCurrent(gun data.GUN, role data.RoleName) (*time.Time, []byte, error) { id := entryKey(gun, role) st.lock.Lock() defer st.lock.Unlock() space, ok := st.tufMeta[id] if !ok || len(space) == 0 { return nil, nil, ErrNotFound{} } return &(space[len(space)-1].createupdate), space[len(space)-1].data, nil }
go
func (st *MemStorage) GetCurrent(gun data.GUN, role data.RoleName) (*time.Time, []byte, error) { id := entryKey(gun, role) st.lock.Lock() defer st.lock.Unlock() space, ok := st.tufMeta[id] if !ok || len(space) == 0 { return nil, nil, ErrNotFound{} } return &(space[len(space)-1].createupdate), space[len(space)-1].data, nil }
[ "func", "(", "st", "*", "MemStorage", ")", "GetCurrent", "(", "gun", "data", ".", "GUN", ",", "role", "data", ".", "RoleName", ")", "(", "*", "time", ".", "Time", ",", "[", "]", "byte", ",", "error", ")", "{", "id", ":=", "entryKey", "(", "gun", ...
// GetCurrent returns the createupdate date metadata for a given role, under a GUN.
[ "GetCurrent", "returns", "the", "createupdate", "date", "metadata", "for", "a", "given", "role", "under", "a", "GUN", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/memory.go#L150-L159
train
theupdateframework/notary
server/storage/memory.go
GetChecksum
func (st *MemStorage) GetChecksum(gun data.GUN, role data.RoleName, checksum string) (*time.Time, []byte, error) { st.lock.Lock() defer st.lock.Unlock() space, ok := st.checksums[gun.String()][checksum] if !ok || len(space.data) == 0 { return nil, nil, ErrNotFound{} } return &(space.createupdate), space.data, nil }
go
func (st *MemStorage) GetChecksum(gun data.GUN, role data.RoleName, checksum string) (*time.Time, []byte, error) { st.lock.Lock() defer st.lock.Unlock() space, ok := st.checksums[gun.String()][checksum] if !ok || len(space.data) == 0 { return nil, nil, ErrNotFound{} } return &(space.createupdate), space.data, nil }
[ "func", "(", "st", "*", "MemStorage", ")", "GetChecksum", "(", "gun", "data", ".", "GUN", ",", "role", "data", ".", "RoleName", ",", "checksum", "string", ")", "(", "*", "time", ".", "Time", ",", "[", "]", "byte", ",", "error", ")", "{", "st", "....
// GetChecksum returns the createupdate date and metadata for a given role, under a GUN.
[ "GetChecksum", "returns", "the", "createupdate", "date", "and", "metadata", "for", "a", "given", "role", "under", "a", "GUN", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/memory.go#L162-L170
train
theupdateframework/notary
server/storage/memory.go
Delete
func (st *MemStorage) Delete(gun data.GUN) error { st.lock.Lock() defer st.lock.Unlock() l := len(st.tufMeta) for k := range st.tufMeta { if strings.HasPrefix(k, gun.String()) { delete(st.tufMeta, k) } } if l == len(st.tufMeta) { // we didn't delete anything, don't write change. return nil } delete(st.checksums, gun.String()) c := Change{ ID: strconv.Itoa(len(st.changes) + 1), GUN: gun.String(), Category: changeCategoryDeletion, CreatedAt: time.Now(), } st.changes = append(st.changes, c) return nil }
go
func (st *MemStorage) Delete(gun data.GUN) error { st.lock.Lock() defer st.lock.Unlock() l := len(st.tufMeta) for k := range st.tufMeta { if strings.HasPrefix(k, gun.String()) { delete(st.tufMeta, k) } } if l == len(st.tufMeta) { // we didn't delete anything, don't write change. return nil } delete(st.checksums, gun.String()) c := Change{ ID: strconv.Itoa(len(st.changes) + 1), GUN: gun.String(), Category: changeCategoryDeletion, CreatedAt: time.Now(), } st.changes = append(st.changes, c) return nil }
[ "func", "(", "st", "*", "MemStorage", ")", "Delete", "(", "gun", "data", ".", "GUN", ")", "error", "{", "st", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "st", ".", "lock", ".", "Unlock", "(", ")", "\n", "l", ":=", "len", "(", "st", "....
// Delete deletes all the metadata for a given GUN
[ "Delete", "deletes", "all", "the", "metadata", "for", "a", "given", "GUN" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/memory.go#L188-L210
train
theupdateframework/notary
passphrase/passphrase.go
PromptRetriever
func PromptRetriever() notary.PassRetriever { if !terminal.IsTerminal(int(os.Stdin.Fd())) { return func(string, string, bool, int) (string, bool, error) { return "", false, ErrNoInput } } return PromptRetrieverWithInOut(os.Stdin, os.Stdout, nil) }
go
func PromptRetriever() notary.PassRetriever { if !terminal.IsTerminal(int(os.Stdin.Fd())) { return func(string, string, bool, int) (string, bool, error) { return "", false, ErrNoInput } } return PromptRetrieverWithInOut(os.Stdin, os.Stdout, nil) }
[ "func", "PromptRetriever", "(", ")", "notary", ".", "PassRetriever", "{", "if", "!", "terminal", ".", "IsTerminal", "(", "int", "(", "os", ".", "Stdin", ".", "Fd", "(", ")", ")", ")", "{", "return", "func", "(", "string", ",", "string", ",", "bool", ...
// PromptRetriever returns a new Retriever which will provide a prompt on stdin // and stdout to retrieve a passphrase. stdin will be checked if it is a terminal, // else the PromptRetriever will error when attempting to retrieve a passphrase. // Upon successful passphrase retrievals, the passphrase will be cached such that // subsequent prompts will produce the same passphrase.
[ "PromptRetriever", "returns", "a", "new", "Retriever", "which", "will", "provide", "a", "prompt", "on", "stdin", "and", "stdout", "to", "retrieve", "a", "passphrase", ".", "stdin", "will", "be", "checked", "if", "it", "is", "a", "terminal", "else", "the", ...
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/passphrase/passphrase.go#L51-L58
train
theupdateframework/notary
passphrase/passphrase.go
PromptRetrieverWithInOut
func PromptRetrieverWithInOut(in io.Reader, out io.Writer, aliasMap map[string]string) notary.PassRetriever { bound := &boundRetriever{ in: in, out: out, aliasMap: aliasMap, passphraseCache: make(map[string]string), } return bound.getPassphrase }
go
func PromptRetrieverWithInOut(in io.Reader, out io.Writer, aliasMap map[string]string) notary.PassRetriever { bound := &boundRetriever{ in: in, out: out, aliasMap: aliasMap, passphraseCache: make(map[string]string), } return bound.getPassphrase }
[ "func", "PromptRetrieverWithInOut", "(", "in", "io", ".", "Reader", ",", "out", "io", ".", "Writer", ",", "aliasMap", "map", "[", "string", "]", "string", ")", "notary", ".", "PassRetriever", "{", "bound", ":=", "&", "boundRetriever", "{", "in", ":", "in...
// PromptRetrieverWithInOut returns a new Retriever which will provide a // prompt using the given in and out readers. The passphrase will be cached // such that subsequent prompts will produce the same passphrase. // aliasMap can be used to specify display names for TUF key aliases. If aliasMap // is nil, a sensible default will be used.
[ "PromptRetrieverWithInOut", "returns", "a", "new", "Retriever", "which", "will", "provide", "a", "prompt", "using", "the", "given", "in", "and", "out", "readers", ".", "The", "passphrase", "will", "be", "cached", "such", "that", "subsequent", "prompts", "will", ...
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/passphrase/passphrase.go#L176-L185
train
theupdateframework/notary
passphrase/passphrase.go
ConstantRetriever
func ConstantRetriever(constantPassphrase string) notary.PassRetriever { return func(k, a string, c bool, n int) (string, bool, error) { return constantPassphrase, false, nil } }
go
func ConstantRetriever(constantPassphrase string) notary.PassRetriever { return func(k, a string, c bool, n int) (string, bool, error) { return constantPassphrase, false, nil } }
[ "func", "ConstantRetriever", "(", "constantPassphrase", "string", ")", "notary", ".", "PassRetriever", "{", "return", "func", "(", "k", ",", "a", "string", ",", "c", "bool", ",", "n", "int", ")", "(", "string", ",", "bool", ",", "error", ")", "{", "ret...
// ConstantRetriever returns a new Retriever which will return a constant string // as a passphrase.
[ "ConstantRetriever", "returns", "a", "new", "Retriever", "which", "will", "return", "a", "constant", "string", "as", "a", "passphrase", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/passphrase/passphrase.go#L189-L193
train
theupdateframework/notary
passphrase/passphrase.go
GetPassphrase
func GetPassphrase(in *bufio.Reader) ([]byte, error) { var ( passphrase []byte err error ) if terminal.IsTerminal(int(os.Stdin.Fd())) { passphrase, err = terminal.ReadPassword(int(os.Stdin.Fd())) } else { passphrase, err = in.ReadBytes('\n') } return passphrase, err }
go
func GetPassphrase(in *bufio.Reader) ([]byte, error) { var ( passphrase []byte err error ) if terminal.IsTerminal(int(os.Stdin.Fd())) { passphrase, err = terminal.ReadPassword(int(os.Stdin.Fd())) } else { passphrase, err = in.ReadBytes('\n') } return passphrase, err }
[ "func", "GetPassphrase", "(", "in", "*", "bufio", ".", "Reader", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "(", "passphrase", "[", "]", "byte", "\n", "err", "error", "\n", ")", "\n", "if", "terminal", ".", "IsTerminal", "(", "int",...
// GetPassphrase get the passphrase from bufio.Reader or from terminal. // If typing on the terminal, we disable terminal to echo the passphrase.
[ "GetPassphrase", "get", "the", "passphrase", "from", "bufio", ".", "Reader", "or", "from", "terminal", ".", "If", "typing", "on", "the", "terminal", "we", "disable", "terminal", "to", "echo", "the", "passphrase", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/passphrase/passphrase.go#L197-L210
train
theupdateframework/notary
tuf/validation/errors.go
UnmarshalJSON
func (s *SerializableError) UnmarshalJSON(text []byte) (err error) { var x struct{ Name string } err = json.Unmarshal(text, &x) if err != nil { return } var theError error switch x.Name { case "ErrValidation": var e struct{ Error ErrValidation } err = json.Unmarshal(text, &e) theError = e.Error case "ErrBadHierarchy": var e struct{ Error ErrBadHierarchy } err = json.Unmarshal(text, &e) theError = e.Error case "ErrBadRoot": var e struct{ Error ErrBadRoot } err = json.Unmarshal(text, &e) theError = e.Error case "ErrBadTargets": var e struct{ Error ErrBadTargets } err = json.Unmarshal(text, &e) theError = e.Error case "ErrBadSnapshot": var e struct{ Error ErrBadSnapshot } err = json.Unmarshal(text, &e) theError = e.Error default: err = fmt.Errorf("do not know how to unmarshal %s", x.Name) return } if err != nil { return } s.Name = x.Name s.Error = theError return nil }
go
func (s *SerializableError) UnmarshalJSON(text []byte) (err error) { var x struct{ Name string } err = json.Unmarshal(text, &x) if err != nil { return } var theError error switch x.Name { case "ErrValidation": var e struct{ Error ErrValidation } err = json.Unmarshal(text, &e) theError = e.Error case "ErrBadHierarchy": var e struct{ Error ErrBadHierarchy } err = json.Unmarshal(text, &e) theError = e.Error case "ErrBadRoot": var e struct{ Error ErrBadRoot } err = json.Unmarshal(text, &e) theError = e.Error case "ErrBadTargets": var e struct{ Error ErrBadTargets } err = json.Unmarshal(text, &e) theError = e.Error case "ErrBadSnapshot": var e struct{ Error ErrBadSnapshot } err = json.Unmarshal(text, &e) theError = e.Error default: err = fmt.Errorf("do not know how to unmarshal %s", x.Name) return } if err != nil { return } s.Name = x.Name s.Error = theError return nil }
[ "func", "(", "s", "*", "SerializableError", ")", "UnmarshalJSON", "(", "text", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "var", "x", "struct", "{", "Name", "string", "}", "\n", "err", "=", "json", ".", "Unmarshal", "(", "text", ",", "&"...
// UnmarshalJSON attempts to unmarshal the error into the right type
[ "UnmarshalJSON", "attempts", "to", "unmarshal", "the", "error", "into", "the", "right", "type" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/validation/errors.go#L67-L105
train
theupdateframework/notary
tuf/validation/errors.go
NewSerializableError
func NewSerializableError(err error) (*SerializableError, error) { // make sure it's one of our errors var name string switch err.(type) { case ErrValidation: name = "ErrValidation" case ErrBadHierarchy: name = "ErrBadHierarchy" case ErrBadRoot: name = "ErrBadRoot" case ErrBadTargets: name = "ErrBadTargets" case ErrBadSnapshot: name = "ErrBadSnapshot" default: return nil, fmt.Errorf("does not support serializing non-validation errors") } return &SerializableError{Name: name, Error: err}, nil }
go
func NewSerializableError(err error) (*SerializableError, error) { // make sure it's one of our errors var name string switch err.(type) { case ErrValidation: name = "ErrValidation" case ErrBadHierarchy: name = "ErrBadHierarchy" case ErrBadRoot: name = "ErrBadRoot" case ErrBadTargets: name = "ErrBadTargets" case ErrBadSnapshot: name = "ErrBadSnapshot" default: return nil, fmt.Errorf("does not support serializing non-validation errors") } return &SerializableError{Name: name, Error: err}, nil }
[ "func", "NewSerializableError", "(", "err", "error", ")", "(", "*", "SerializableError", ",", "error", ")", "{", "var", "name", "string", "\n", "switch", "err", ".", "(", "type", ")", "{", "case", "ErrValidation", ":", "name", "=", "\"ErrValidation\"", "\n...
// NewSerializableError serializes one of the above errors into JSON
[ "NewSerializableError", "serializes", "one", "of", "the", "above", "errors", "into", "JSON" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/validation/errors.go#L108-L126
train
theupdateframework/notary
cmd/notary/util.go
getPayload
func getPayload(t *tufCommander) ([]byte, error) { // Reads from the given file if t.input != "" { // Please note that ReadFile will cut off the size if it was over 1e9. // Thus, if the size of the file exceeds 1GB, the over part will not be // loaded into the buffer. payload, err := ioutil.ReadFile(t.input) if err != nil { return nil, err } return payload, nil } // Reads all of the data on STDIN payload, err := ioutil.ReadAll(os.Stdin) if err != nil { return nil, fmt.Errorf("Error reading content from STDIN: %v", err) } return payload, nil }
go
func getPayload(t *tufCommander) ([]byte, error) { // Reads from the given file if t.input != "" { // Please note that ReadFile will cut off the size if it was over 1e9. // Thus, if the size of the file exceeds 1GB, the over part will not be // loaded into the buffer. payload, err := ioutil.ReadFile(t.input) if err != nil { return nil, err } return payload, nil } // Reads all of the data on STDIN payload, err := ioutil.ReadAll(os.Stdin) if err != nil { return nil, fmt.Errorf("Error reading content from STDIN: %v", err) } return payload, nil }
[ "func", "getPayload", "(", "t", "*", "tufCommander", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "t", ".", "input", "!=", "\"\"", "{", "payload", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "t", ".", "input", ")", "\n", "if", ...
// getPayload is a helper function to get the content used to be verified // either from an existing file or STDIN.
[ "getPayload", "is", "a", "helper", "function", "to", "get", "the", "content", "used", "to", "be", "verified", "either", "from", "an", "existing", "file", "or", "STDIN", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/cmd/notary/util.go#L17-L37
train
theupdateframework/notary
cmd/notary/util.go
feedback
func feedback(t *tufCommander, payload []byte) error { // We only get here when everything goes well, since the flag "quiet" was // provided, we output nothing but just return. if t.quiet { return nil } // Flag "quiet" was not "true", that's why we get here. if t.output != "" { return ioutil.WriteFile(t.output, payload, 0644) } os.Stdout.Write(payload) return nil }
go
func feedback(t *tufCommander, payload []byte) error { // We only get here when everything goes well, since the flag "quiet" was // provided, we output nothing but just return. if t.quiet { return nil } // Flag "quiet" was not "true", that's why we get here. if t.output != "" { return ioutil.WriteFile(t.output, payload, 0644) } os.Stdout.Write(payload) return nil }
[ "func", "feedback", "(", "t", "*", "tufCommander", ",", "payload", "[", "]", "byte", ")", "error", "{", "if", "t", ".", "quiet", "{", "return", "nil", "\n", "}", "\n", "if", "t", ".", "output", "!=", "\"\"", "{", "return", "ioutil", ".", "WriteFile...
// feedback is a helper function to print the payload to a file or STDOUT or keep quiet // due to the value of flag "quiet" and "output".
[ "feedback", "is", "a", "helper", "function", "to", "print", "the", "payload", "to", "a", "file", "or", "STDOUT", "or", "keep", "quiet", "due", "to", "the", "value", "of", "flag", "quiet", "and", "output", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/cmd/notary/util.go#L41-L55
train
theupdateframework/notary
cmd/notary/util.go
homeExpand
func homeExpand(homeDir, path string) string { if path == "" || path[0] != '~' || (len(path) > 1 && path[1] != os.PathSeparator) { return path } return filepath.Join(homeDir, path[1:]) }
go
func homeExpand(homeDir, path string) string { if path == "" || path[0] != '~' || (len(path) > 1 && path[1] != os.PathSeparator) { return path } return filepath.Join(homeDir, path[1:]) }
[ "func", "homeExpand", "(", "homeDir", ",", "path", "string", ")", "string", "{", "if", "path", "==", "\"\"", "||", "path", "[", "0", "]", "!=", "'~'", "||", "(", "len", "(", "path", ")", ">", "1", "&&", "path", "[", "1", "]", "!=", "os", ".", ...
// homeExpand will expand an initial ~ to the user home directory. This is supported for // config files where the shell will not have expanded paths.
[ "homeExpand", "will", "expand", "an", "initial", "~", "to", "the", "user", "home", "directory", ".", "This", "is", "supported", "for", "config", "files", "where", "the", "shell", "will", "not", "have", "expanded", "paths", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/cmd/notary/util.go#L59-L64
train
theupdateframework/notary
server/handlers/default.go
MainHandler
func MainHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { // For now it only supports `GET` if r.Method != "GET" { return errors.ErrGenericNotFound.WithDetail(nil) } if _, err := w.Write([]byte("{}")); err != nil { return errors.ErrUnknown.WithDetail(err) } return nil }
go
func MainHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { // For now it only supports `GET` if r.Method != "GET" { return errors.ErrGenericNotFound.WithDetail(nil) } if _, err := w.Write([]byte("{}")); err != nil { return errors.ErrUnknown.WithDetail(err) } return nil }
[ "func", "MainHandler", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "if", "r", ".", "Method", "!=", "\"GET\"", "{", "return", "errors", ".", "ErrGenericNotFound"...
// MainHandler is the default handler for the server
[ "MainHandler", "is", "the", "default", "handler", "for", "the", "server" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/handlers/default.go#L28-L38
train
theupdateframework/notary
server/handlers/default.go
AtomicUpdateHandler
func AtomicUpdateHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { defer r.Body.Close() vars := mux.Vars(r) return atomicUpdateHandler(ctx, w, r, vars) }
go
func AtomicUpdateHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { defer r.Body.Close() vars := mux.Vars(r) return atomicUpdateHandler(ctx, w, r, vars) }
[ "func", "AtomicUpdateHandler", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "defer", "r", ".", "Body", ".", "Close", "(", ")", "\n", "vars", ":=", "mux", "."...
// AtomicUpdateHandler will accept multiple TUF files and ensure that the storage // backend is atomically updated with all the new records.
[ "AtomicUpdateHandler", "will", "accept", "multiple", "TUF", "files", "and", "ensure", "that", "the", "storage", "backend", "is", "atomically", "updated", "with", "all", "the", "new", "records", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/handlers/default.go#L42-L46
train
theupdateframework/notary
server/handlers/default.go
logTS
func logTS(logger ctxu.Logger, gun string, updates []storage.MetaUpdate) { for _, update := range updates { if update.Role == data.CanonicalTimestampRole { checksumBin := sha256.Sum256(update.Data) checksum := hex.EncodeToString(checksumBin[:]) logger.Infof("updated %s to timestamp version %d, checksum %s", gun, update.Version, checksum) break } } }
go
func logTS(logger ctxu.Logger, gun string, updates []storage.MetaUpdate) { for _, update := range updates { if update.Role == data.CanonicalTimestampRole { checksumBin := sha256.Sum256(update.Data) checksum := hex.EncodeToString(checksumBin[:]) logger.Infof("updated %s to timestamp version %d, checksum %s", gun, update.Version, checksum) break } } }
[ "func", "logTS", "(", "logger", "ctxu", ".", "Logger", ",", "gun", "string", ",", "updates", "[", "]", "storage", ".", "MetaUpdate", ")", "{", "for", "_", ",", "update", ":=", "range", "updates", "{", "if", "update", ".", "Role", "==", "data", ".", ...
// logTS logs the timestamp update at Info level
[ "logTS", "logs", "the", "timestamp", "update", "at", "Info", "level" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/handlers/default.go#L126-L135
train
theupdateframework/notary
server/handlers/default.go
GetHandler
func GetHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { defer r.Body.Close() vars := mux.Vars(r) return getHandler(ctx, w, r, vars) }
go
func GetHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { defer r.Body.Close() vars := mux.Vars(r) return getHandler(ctx, w, r, vars) }
[ "func", "GetHandler", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "defer", "r", ".", "Body", ".", "Close", "(", ")", "\n", "vars", ":=", "mux", ".", "Vars...
// GetHandler returns the json for a specified role and GUN.
[ "GetHandler", "returns", "the", "json", "for", "a", "specified", "role", "and", "GUN", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/handlers/default.go#L138-L142
train
theupdateframework/notary
server/handlers/default.go
DeleteHandler
func DeleteHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { vars := mux.Vars(r) gun := data.GUN(vars["gun"]) logger := ctxu.GetLoggerWithField(ctx, gun, "gun") s := ctx.Value(notary.CtxKeyMetaStore) store, ok := s.(storage.MetaStore) if !ok { logger.Error("500 DELETE repository: no storage exists") return errors.ErrNoStorage.WithDetail(nil) } err := store.Delete(gun) if err != nil { logger.Error("500 DELETE repository") return errors.ErrUnknown.WithDetail(err) } logger.Infof("trust data deleted for %s", gun) return nil }
go
func DeleteHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { vars := mux.Vars(r) gun := data.GUN(vars["gun"]) logger := ctxu.GetLoggerWithField(ctx, gun, "gun") s := ctx.Value(notary.CtxKeyMetaStore) store, ok := s.(storage.MetaStore) if !ok { logger.Error("500 DELETE repository: no storage exists") return errors.ErrNoStorage.WithDetail(nil) } err := store.Delete(gun) if err != nil { logger.Error("500 DELETE repository") return errors.ErrUnknown.WithDetail(err) } logger.Infof("trust data deleted for %s", gun) return nil }
[ "func", "DeleteHandler", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "vars", ":=", "mux", ".", "Vars", "(", "r", ")", "\n", "gun", ":=", "data", ".", "GUN...
// DeleteHandler deletes all data for a GUN. A 200 responses indicates success.
[ "DeleteHandler", "deletes", "all", "data", "for", "a", "GUN", ".", "A", "200", "responses", "indicates", "success", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/handlers/default.go#L179-L196
train
theupdateframework/notary
server/handlers/default.go
GetKeyHandler
func GetKeyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { defer r.Body.Close() vars := mux.Vars(r) return getKeyHandler(ctx, w, r, vars) }
go
func GetKeyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { defer r.Body.Close() vars := mux.Vars(r) return getKeyHandler(ctx, w, r, vars) }
[ "func", "GetKeyHandler", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "defer", "r", ".", "Body", ".", "Close", "(", ")", "\n", "vars", ":=", "mux", ".", "V...
// GetKeyHandler returns a public key for the specified role, creating a new key-pair // it if it doesn't yet exist
[ "GetKeyHandler", "returns", "a", "public", "key", "for", "the", "specified", "role", "creating", "a", "new", "key", "-", "pair", "it", "if", "it", "doesn", "t", "yet", "exist" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/handlers/default.go#L200-L204
train
theupdateframework/notary
server/handlers/default.go
RotateKeyHandler
func RotateKeyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { defer r.Body.Close() vars := mux.Vars(r) return rotateKeyHandler(ctx, w, r, vars) }
go
func RotateKeyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { defer r.Body.Close() vars := mux.Vars(r) return rotateKeyHandler(ctx, w, r, vars) }
[ "func", "RotateKeyHandler", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "defer", "r", ".", "Body", ".", "Close", "(", ")", "\n", "vars", ":=", "mux", ".", ...
// RotateKeyHandler rotates the remote key for the specified role, returning the public key
[ "RotateKeyHandler", "rotates", "the", "remote", "key", "for", "the", "specified", "role", "returning", "the", "public", "key" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/handlers/default.go#L238-L242
train
theupdateframework/notary
server/handlers/default.go
setupKeyHandler
func setupKeyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string, actionVerb string) (data.RoleName, data.GUN, string, storage.MetaStore, signed.CryptoService, error) { gun := data.GUN(vars["gun"]) logger := ctxu.GetLoggerWithField(ctx, gun, "gun") if gun == "" { logger.Infof("400 %s no gun in request", actionVerb) return "", "", "", nil, nil, errors.ErrUnknown.WithDetail("no gun") } role := data.RoleName(vars["tufRole"]) if role == "" { logger.Infof("400 %s no role in request", actionVerb) return "", "", "", nil, nil, errors.ErrUnknown.WithDetail("no role") } s := ctx.Value(notary.CtxKeyMetaStore) store, ok := s.(storage.MetaStore) if !ok || store == nil { logger.Errorf("500 %s storage not configured", actionVerb) return "", "", "", nil, nil, errors.ErrNoStorage.WithDetail(nil) } c := ctx.Value(notary.CtxKeyCryptoSvc) crypto, ok := c.(signed.CryptoService) if !ok || crypto == nil { logger.Errorf("500 %s crypto service not configured", actionVerb) return "", "", "", nil, nil, errors.ErrNoCryptoService.WithDetail(nil) } algo := ctx.Value(notary.CtxKeyKeyAlgo) keyAlgo, ok := algo.(string) if !ok || keyAlgo == "" { logger.Errorf("500 %s key algorithm not configured", actionVerb) return "", "", "", nil, nil, errors.ErrNoKeyAlgorithm.WithDetail(nil) } return role, gun, keyAlgo, store, crypto, nil }
go
func setupKeyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string, actionVerb string) (data.RoleName, data.GUN, string, storage.MetaStore, signed.CryptoService, error) { gun := data.GUN(vars["gun"]) logger := ctxu.GetLoggerWithField(ctx, gun, "gun") if gun == "" { logger.Infof("400 %s no gun in request", actionVerb) return "", "", "", nil, nil, errors.ErrUnknown.WithDetail("no gun") } role := data.RoleName(vars["tufRole"]) if role == "" { logger.Infof("400 %s no role in request", actionVerb) return "", "", "", nil, nil, errors.ErrUnknown.WithDetail("no role") } s := ctx.Value(notary.CtxKeyMetaStore) store, ok := s.(storage.MetaStore) if !ok || store == nil { logger.Errorf("500 %s storage not configured", actionVerb) return "", "", "", nil, nil, errors.ErrNoStorage.WithDetail(nil) } c := ctx.Value(notary.CtxKeyCryptoSvc) crypto, ok := c.(signed.CryptoService) if !ok || crypto == nil { logger.Errorf("500 %s crypto service not configured", actionVerb) return "", "", "", nil, nil, errors.ErrNoCryptoService.WithDetail(nil) } algo := ctx.Value(notary.CtxKeyKeyAlgo) keyAlgo, ok := algo.(string) if !ok || keyAlgo == "" { logger.Errorf("500 %s key algorithm not configured", actionVerb) return "", "", "", nil, nil, errors.ErrNoKeyAlgorithm.WithDetail(nil) } return role, gun, keyAlgo, store, crypto, nil }
[ "func", "setupKeyHandler", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "vars", "map", "[", "string", "]", "string", ",", "actionVerb", "string", ")", "(", "data", ".", "Rol...
// To be called before getKeyHandler or rotateKeyHandler
[ "To", "be", "called", "before", "getKeyHandler", "or", "rotateKeyHandler" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/handlers/default.go#L276-L310
train
theupdateframework/notary
server/handlers/default.go
NotFoundHandler
func NotFoundHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { return errors.ErrMetadataNotFound.WithDetail(nil) }
go
func NotFoundHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error { return errors.ErrMetadataNotFound.WithDetail(nil) }
[ "func", "NotFoundHandler", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "return", "errors", ".", "ErrMetadataNotFound", ".", "WithDetail", "(", "nil", ")", "\n", ...
// NotFoundHandler is used as a generic catch all handler to return the ErrMetadataNotFound // 404 response
[ "NotFoundHandler", "is", "used", "as", "a", "generic", "catch", "all", "handler", "to", "return", "the", "ErrMetadataNotFound", "404", "response" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/handlers/default.go#L314-L316
train
theupdateframework/notary
server/storage/sqldb.go
NewSQLStorage
func NewSQLStorage(dialect string, args ...interface{}) (*SQLStorage, error) { gormDB, err := gorm.Open(dialect, args...) if err != nil { return nil, err } return &SQLStorage{ DB: *gormDB, }, nil }
go
func NewSQLStorage(dialect string, args ...interface{}) (*SQLStorage, error) { gormDB, err := gorm.Open(dialect, args...) if err != nil { return nil, err } return &SQLStorage{ DB: *gormDB, }, nil }
[ "func", "NewSQLStorage", "(", "dialect", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "*", "SQLStorage", ",", "error", ")", "{", "gormDB", ",", "err", ":=", "gorm", ".", "Open", "(", "dialect", ",", "args", "...", ")", "\n", "if", ...
// NewSQLStorage is a convenience method to create a SQLStorage
[ "NewSQLStorage", "is", "a", "convenience", "method", "to", "create", "a", "SQLStorage" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/sqldb.go#L23-L31
train