diff options
| author | Andrew Wilkins <axwalk@gmail.com> | 2016-03-15 05:36:43 +0000 |
|---|---|---|
| committer | Andrew Wilkins <axwalk@gmail.com> | 2016-03-15 05:36:43 +0000 |
| commit | 6436a4abd7a2f3a60b230453295dba199d8a59c3 (patch) | |
| tree | 125aef80fc2cf46c5d1758a8ece1fde14e7b13fd /llgo/third_party/gofrontend/libgo/go/encoding/pem/pem.go | |
| parent | 36761bf92427846ce40fdd849615732c852e44dd (diff) | |
| download | bcm5719-llvm-6436a4abd7a2f3a60b230453295dba199d8a59c3.tar.gz bcm5719-llvm-6436a4abd7a2f3a60b230453295dba199d8a59c3.zip | |
[llgo] Roll gofrontend forward
Switch gofrontend to using go.googlesource.com, and
update to 81eb6a3f425b2158c67ee32c0cc973a72ce9d6be.
There are various changes required to update to the
go 1.5 runtime:
typemap.go is changed to accommodate the change in representation for equal/hash algorithms, and the removal of the zero value/type.
CMakeLists.txt is updated to add the build tree to the package search path, so internal packages, which are not installed, are found.
various files changes due to removal of __go_new_nopointers; the same change as in D11863, but with NoUnwindAttribute added to the added runtime functions which are called with "callOnly".
minor cleanups in ssa.go while investigating issues with unwinding/panic handling.
Differential Revisision: http://reviews.llvm.org/D15188
llvm-svn: 263536
Diffstat (limited to 'llgo/third_party/gofrontend/libgo/go/encoding/pem/pem.go')
| -rw-r--r-- | llgo/third_party/gofrontend/libgo/go/encoding/pem/pem.go | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/llgo/third_party/gofrontend/libgo/go/encoding/pem/pem.go b/llgo/third_party/gofrontend/libgo/go/encoding/pem/pem.go index 8ff7ee8c33a..506196b1db9 100644 --- a/llgo/third_party/gofrontend/libgo/go/encoding/pem/pem.go +++ b/llgo/third_party/gofrontend/libgo/go/encoding/pem/pem.go @@ -10,8 +10,10 @@ package pem import ( "bytes" "encoding/base64" + "errors" "io" "sort" + "strings" ) // A Block represents a PEM encoded structure. @@ -110,27 +112,37 @@ func Decode(data []byte) (p *Block, rest []byte) { } // TODO(agl): need to cope with values that spread across lines. - key, val := line[0:i], line[i+1:] + key, val := line[:i], line[i+1:] key = bytes.TrimSpace(key) val = bytes.TrimSpace(val) p.Headers[string(key)] = string(val) rest = next } - i := bytes.Index(rest, pemEnd) - if i < 0 { + var endIndex int + // If there were no headers, the END line might occur + // immediately, without a leading newline. + if len(p.Headers) == 0 && bytes.HasPrefix(rest, pemEnd[1:]) { + endIndex = 0 + } else { + endIndex = bytes.Index(rest, pemEnd) + } + + if endIndex < 0 { return decodeError(data, rest) } - base64Data := removeWhitespace(rest[0:i]) + base64Data := removeWhitespace(rest[:endIndex]) p.Bytes = make([]byte, base64.StdEncoding.DecodedLen(len(base64Data))) n, err := base64.StdEncoding.Decode(p.Bytes, base64Data) if err != nil { return decodeError(data, rest) } - p.Bytes = p.Bytes[0:n] + p.Bytes = p.Bytes[:n] - _, rest = getLine(rest[i+len(pemEnd):]) + // the -1 is because we might have only matched pemEnd without the + // leading newline if the PEM block was empty. + _, rest = getLine(rest[endIndex+len(pemEnd)-1:]) return } @@ -171,6 +183,8 @@ type lineBreaker struct { out io.Writer } +var nl = []byte{'\n'} + func (l *lineBreaker) Write(b []byte) (n int, err error) { if l.used+len(b) < pemLineLength { copy(l.line[l.used:], b) @@ -190,7 +204,7 @@ func (l *lineBreaker) Write(b []byte) (n int, err error) { return } - n, err = l.out.Write([]byte{'\n'}) + n, err = l.out.Write(nl) if err != nil { return } @@ -204,7 +218,7 @@ func (l *lineBreaker) Close() (err error) { if err != nil { return } - _, err = l.out.Write([]byte{'\n'}) + _, err = l.out.Write(nl) } return @@ -244,11 +258,14 @@ func Encode(out io.Writer, b *Block) error { // For consistency of output, write other headers sorted by key. sort.Strings(h) for _, k := range h { + if strings.Contains(k, ":") { + return errors.New("pem: cannot encode a header key that contains a colon") + } if err := writeHeader(out, k, b.Headers[k]); err != nil { return err } } - if _, err := out.Write([]byte{'\n'}); err != nil { + if _, err := out.Write(nl); err != nil { return err } } |

