mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 21:44:23 +01:00
1 parent
8eb28cbb4c
commit
fad98cbde2
216 files changed
+27523
-3828
No files matched your search
+29
-28
@@ -17,8 +17,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
beginpgp string = "-----BEGIN PGP SIGNATURE-----"
|
||||
endpgp string = "-----END PGP SIGNATURE-----"
|
||||
beginpgp string = "-----BEGIN PGP SIGNATURE-----"
|
||||
endpgp string = "-----END PGP SIGNATURE-----"
|
||||
headerpgp string = "gpgsig"
|
||||
)
|
||||
|
||||
// Hash represents the hash of an object
|
||||
@@ -181,23 +182,13 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
|
||||
}
|
||||
|
||||
if pgpsig {
|
||||
// Check if it's the end of a PGP signature.
|
||||
if bytes.Contains(line, []byte(endpgp)) {
|
||||
c.PGPSignature += endpgp + "\n"
|
||||
pgpsig = false
|
||||
} else {
|
||||
// Trim the left padding.
|
||||
if len(line) > 0 && line[0] == ' ' {
|
||||
line = bytes.TrimLeft(line, " ")
|
||||
c.PGPSignature += string(line)
|
||||
continue
|
||||
} else {
|
||||
pgpsig = false
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if it's the beginning of a PGP signature.
|
||||
if bytes.Contains(line, []byte(beginpgp)) {
|
||||
c.PGPSignature += beginpgp + "\n"
|
||||
pgpsig = true
|
||||
continue
|
||||
}
|
||||
|
||||
if !message {
|
||||
@@ -208,15 +199,24 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
|
||||
}
|
||||
|
||||
split := bytes.SplitN(line, []byte{' '}, 2)
|
||||
|
||||
var data []byte
|
||||
if len(split) == 2 {
|
||||
data = split[1]
|
||||
}
|
||||
|
||||
switch string(split[0]) {
|
||||
case "tree":
|
||||
c.TreeHash = plumbing.NewHash(string(split[1]))
|
||||
c.TreeHash = plumbing.NewHash(string(data))
|
||||
case "parent":
|
||||
c.ParentHashes = append(c.ParentHashes, plumbing.NewHash(string(split[1])))
|
||||
c.ParentHashes = append(c.ParentHashes, plumbing.NewHash(string(data)))
|
||||
case "author":
|
||||
c.Author.Decode(split[1])
|
||||
c.Author.Decode(data)
|
||||
case "committer":
|
||||
c.Committer.Decode(split[1])
|
||||
c.Committer.Decode(data)
|
||||
case headerpgp:
|
||||
c.PGPSignature += string(data) + "\n"
|
||||
pgpsig = true
|
||||
}
|
||||
} else {
|
||||
c.Message += string(line)
|
||||
@@ -269,17 +269,18 @@ func (b *Commit) encode(o plumbing.EncodedObject, includeSig bool) (err error) {
|
||||
}
|
||||
|
||||
if b.PGPSignature != "" && includeSig {
|
||||
if _, err = fmt.Fprint(w, "pgpsig"); err != nil {
|
||||
if _, err = fmt.Fprint(w, "\n"+headerpgp+" "); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Split all the signature lines and write with a left padding and
|
||||
// newline at the end.
|
||||
lines := strings.Split(b.PGPSignature, "\n")
|
||||
for _, line := range lines {
|
||||
if _, err = fmt.Fprintf(w, " %s\n", line); err != nil {
|
||||
return err
|
||||
}
|
||||
// Split all the signature lines and re-write with a left padding and
|
||||
// newline. Use join for this so it's clear that a newline should not be
|
||||
// added after this section, as it will be added when the message is
|
||||
// printed.
|
||||
signature := strings.TrimSuffix(b.PGPSignature, "\n")
|
||||
lines := strings.Split(signature, "\n")
|
||||
if _, err = fmt.Fprint(w, strings.Join(lines, "\n ")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -152,7 +152,11 @@ func (s *Signature) decodeTimeAndTimeZone(b []byte) {
|
||||
}
|
||||
|
||||
func (s *Signature) encodeTimeAndTimeZone(w io.Writer) error {
|
||||
_, err := fmt.Fprintf(w, "%d %s", s.When.Unix(), s.When.Format("-0700"))
|
||||
u := s.When.Unix()
|
||||
if u < 0 {
|
||||
u = 0
|
||||
}
|
||||
_, err := fmt.Fprintf(w, "%d %s", u, s.When.Format("-0700"))
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -26,6 +26,7 @@ var (
|
||||
ErrMaxTreeDepth = errors.New("maximum tree depth exceeded")
|
||||
ErrFileNotFound = errors.New("file not found")
|
||||
ErrDirectoryNotFound = errors.New("directory not found")
|
||||
ErrEntryNotFound = errors.New("entry not found")
|
||||
)
|
||||
|
||||
// Tree is basically like a directory - it references a bunch of other trees
|
||||
@@ -167,8 +168,6 @@ func (t *Tree) dir(baseName string) (*Tree, error) {
|
||||
return tree, err
|
||||
}
|
||||
|
||||
var errEntryNotFound = errors.New("entry not found")
|
||||
|
||||
func (t *Tree) entry(baseName string) (*TreeEntry, error) {
|
||||
if t.m == nil {
|
||||
t.buildMap()
|
||||
@@ -176,7 +175,7 @@ func (t *Tree) entry(baseName string) (*TreeEntry, error) {
|
||||
|
||||
entry, ok := t.m[baseName]
|
||||
if !ok {
|
||||
return nil, errEntryNotFound
|
||||
return nil, ErrEntryNotFound
|
||||
}
|
||||
|
||||
return entry, nil
|
||||
|
||||
Reference in new issue
Block a user