dehub/commit_credential.go
mediocregopher 69e336ea5e rename commit_signature.go to commit_credential.go
---
type: change
message: rename commit_signature.go to commit_credential.go
change_hash: AOU9vhAVaw7b8KQuFB4vyrKZo9+rWt7qefSpUcT00Ntn
credentials:
- type: pgp_signature
  pub_key_id: 95C46FA6A41148AC
  body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl5tFpUACgkQlcRvpqQRSKwgNQ//VpGeG3nZQzPq6dTEteTjKVC6uUCeRIViLWXJ8ZtQ+ffmTtTVweV7FkQ9ti3O9rx7UzJy06VoDti/pRLQ5FiG0fUO53c3rk6GOih7d+pu1Sg0/7IkcIWe9m5M6SPGDTtQrUeCQGSiBNUL/dzu2EDaBtEDyiVng59kJuy7h5zxjOQ2VTd/MpuIE+h0h+B+qo01OTme2P/YZVEmKbQl424C84TBlK4lL19yAMhBxFWNH/mrz+poR/dWCcDxMgaL0hlPuUon25+VTJfL0EPy5XsDIZCqKNuj4WUXwI27mwDCEuvV4WOthbUtwVYOUAEqQNoiL7wDfsnWseW73qMfUDFsa0IBpW2LUGl45SDxPZTar5cEIQAriaKFC274f4w+bIf6c38AFVOqLg8TCMvbMXyWj7cfJ99qA/pLkFxLtLWt+TPeVN3qnkLlHeUjb4+s+IVY0bPoh32UnomCh3DyJzvughxaN4nZOISh688SnSmLpyDLkhAAVZf0n3sG4t7uARaUv4vSZtNMxJpRVrymzhRHGd2AHVMeyWf0UCMU9wqJPE713FPCTrdeqbwzWXslHptHnuFKLuizzQ39ScjukVu9oin6rnbH4UIqY2CUi8BzQJpOsaj+iq0p4R87dBj/uKlKLvm0zxzYK1rD9L6oZ3PKbJ5meW8kX2u24dD+0pxN2lI=
  account: mediocregopher
2020-03-14 11:38:35 -06:00

47 lines
1.3 KiB
Go

package dehub
import (
"dehub/yamlutil"
"encoding/base64"
"fmt"
"gopkg.in/src-d/go-git.v4/plumbing/object"
)
// CommitCredential describes the structure of a credential commit message.
type CommitCredential struct {
CredentialedHash yamlutil.Blob `yaml:"credentialed_hash"`
}
var _ CommitInterface = CommitCredential{}
// NewCommitCredential constructs and returns a Commit populated with a
// CommitCredential encompassing the given hash. The Credentials of the returned
// Commit will _not_ be filled in.
func (r *Repo) NewCommitCredential(hash []byte) (Commit, error) {
return Commit{
Credential: &CommitCredential{
CredentialedHash: hash,
},
}, nil
}
// MessageHead implements the method for the CommitInterface interface.
func (cc CommitCredential) MessageHead() (string, error) {
hash64 := base64.StdEncoding.EncodeToString(cc.CredentialedHash)
if len(hash64) > 6 {
hash64 = hash64[:6] + "..."
}
return fmt.Sprintf("Credential of hash %s", hash64), nil
}
// Hash implements the method for the CommitInterface.
func (cc CommitCredential) Hash(_, _ *object.Tree) ([]byte, error) {
return cc.CredentialedHash, nil
}
// GetHash implements the method for the CommitInterface.
func (cc CommitCredential) GetHash() []byte {
return cc.CredentialedHash
}