check hosts in ssl certificates
This commit is contained in:
77
vendor/github.com/cavaliercoder/go-cpio/example_test.go
generated
vendored
77
vendor/github.com/cavaliercoder/go-cpio/example_test.go
generated
vendored
@ -1,77 +0,0 @@
|
||||
package cpio_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/cavaliercoder/go-cpio"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
// Create a buffer to write our archive to.
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
// Create a new cpio archive.
|
||||
w := cpio.NewWriter(buf)
|
||||
|
||||
// Add some files to the archive.
|
||||
var files = []struct {
|
||||
Name, Body string
|
||||
}{
|
||||
{"readme.txt", "This archive contains some text files."},
|
||||
{"gopher.txt", "Gopher names:\nGeorge\nGeoffrey\nGonzo"},
|
||||
{"todo.txt", "Get animal handling license."},
|
||||
}
|
||||
for _, file := range files {
|
||||
hdr := &cpio.Header{
|
||||
Name: file.Name,
|
||||
Mode: 0600,
|
||||
Size: int64(len(file.Body)),
|
||||
}
|
||||
if err := w.WriteHeader(hdr); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
if _, err := w.Write([]byte(file.Body)); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
// Make sure to check the error on Close.
|
||||
if err := w.Close(); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
// Open the cpio archive for reading.
|
||||
b := bytes.NewReader(buf.Bytes())
|
||||
r := cpio.NewReader(b)
|
||||
|
||||
// Iterate through the files in the archive.
|
||||
for {
|
||||
hdr, err := r.Next()
|
||||
if err == io.EOF {
|
||||
// end of cpio archive
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
fmt.Printf("Contents of %s:\n", hdr.Name)
|
||||
if _, err := io.Copy(os.Stdout, r); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
// Output:
|
||||
// Contents of readme.txt:
|
||||
// This archive contains some text files.
|
||||
// Contents of gopher.txt:
|
||||
// Gopher names:
|
||||
// George
|
||||
// Geoffrey
|
||||
// Gonzo
|
||||
// Contents of todo.txt:
|
||||
// Get animal handling license.
|
||||
}
|
121
vendor/github.com/cavaliercoder/go-cpio/svr4_test.go
generated
vendored
121
vendor/github.com/cavaliercoder/go-cpio/svr4_test.go
generated
vendored
@ -1,121 +0,0 @@
|
||||
package cpio
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var files = []struct {
|
||||
Name, Body string
|
||||
}{
|
||||
{"./gophers.txt", "Gopher names:\nGeorge\nGeoffrey\nGonzo"},
|
||||
{"./readme.txt", "This archive contains some text files."},
|
||||
{"./todo.txt", "Get animal handling license."},
|
||||
}
|
||||
|
||||
func TestRead(t *testing.T) {
|
||||
f, err := os.Open("testdata/test_svr4_crc.cpio")
|
||||
if err != nil {
|
||||
t.Fatalf("error opening test file: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
r := NewReader(f)
|
||||
for {
|
||||
_, err := r.Next()
|
||||
if err == io.EOF {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("error moving to next header: %v", err)
|
||||
return
|
||||
}
|
||||
// TODO: validate header fields
|
||||
}
|
||||
}
|
||||
|
||||
func TestSVR4CRC(t *testing.T) {
|
||||
f, err := os.Open("testdata/test_svr4_crc.cpio")
|
||||
if err != nil {
|
||||
t.Fatalf("error opening test file: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
w := NewHash()
|
||||
r := NewReader(f)
|
||||
for {
|
||||
hdr, err := r.Next()
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
t.Errorf("error moving to next header: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if hdr.Mode.IsRegular() {
|
||||
w.Reset()
|
||||
_, err = io.CopyN(w, r, hdr.Size)
|
||||
if err != nil {
|
||||
t.Fatalf("error writing to checksum hash: %v", err)
|
||||
}
|
||||
|
||||
sum := Checksum(w.Sum32())
|
||||
if sum != hdr.Checksum {
|
||||
t.Errorf("expected checksum %v, got %v for %v", hdr.Checksum, sum, hdr.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleNewHash() {
|
||||
// Open the cpio archive for reading.
|
||||
f, err := os.Open("testdata/test_svr4_crc.cpio")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
r := NewReader(f)
|
||||
|
||||
// create a Hash
|
||||
h := NewHash()
|
||||
|
||||
// Iterate through the files in the archive.
|
||||
for {
|
||||
hdr, err := r.Next()
|
||||
if err == io.EOF {
|
||||
// end of cpio archive
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// skip symlinks, directories, etc.
|
||||
if !hdr.Mode.IsRegular() {
|
||||
continue
|
||||
}
|
||||
|
||||
// read file into hash
|
||||
h.Reset()
|
||||
_, err = io.CopyN(h, r, hdr.Size)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// check hash matches header checksum
|
||||
sum := Checksum(h.Sum32())
|
||||
if sum == hdr.Checksum {
|
||||
fmt.Printf("Checksum OK: %v (%v)\n", hdr.Name, hdr.Checksum)
|
||||
} else {
|
||||
fmt.Printf("Checksum FAIL: %v - expected %v, got %v\n", hdr.Name, hdr.Checksum, sum)
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// Checksum OK: gophers.txt (00000C98)
|
||||
// Checksum OK: readme.txt (00000E3D)
|
||||
// Checksum OK: todo.txt (00000A52)
|
||||
}
|
26
vendor/github.com/cavaliercoder/go-cpio/testdata/Makefile
generated
vendored
26
vendor/github.com/cavaliercoder/go-cpio/testdata/Makefile
generated
vendored
@ -1,26 +0,0 @@
|
||||
SOURCES = \
|
||||
gophers.txt \
|
||||
readme.txt \
|
||||
todo.txt \
|
||||
checklist.txt
|
||||
|
||||
ARCHIVES = \
|
||||
test_odc.cpio \
|
||||
test_svr4.cpio \
|
||||
test_svr4_crc.cpio
|
||||
|
||||
all: $(ARCHIVES)
|
||||
|
||||
test_odc.cpio: $(SOURCES)
|
||||
echo $(SOURCES) | tr " " "\n" | cpio -o --owner=0:0 --format=odc > $@
|
||||
|
||||
test_svr4.cpio: $(SOURCES)
|
||||
echo $(SOURCES) | tr " " "\n" | cpio -o --owner=0:0 --format=newc > $@
|
||||
|
||||
test_svr4_crc.cpio: $(SOURCES)
|
||||
echo $(SOURCES) | tr " " "\n" | cpio -o --owner=0:0 --format=crc > $@
|
||||
|
||||
clean:
|
||||
rm -f $(ARCHIVES) version.txt
|
||||
|
||||
.PHONY: all clean
|
1
vendor/github.com/cavaliercoder/go-cpio/testdata/checklist.txt
generated
vendored
1
vendor/github.com/cavaliercoder/go-cpio/testdata/checklist.txt
generated
vendored
@ -1 +0,0 @@
|
||||
todo.txt
|
2
vendor/github.com/cavaliercoder/go-cpio/testdata/etc/hosts
generated
vendored
2
vendor/github.com/cavaliercoder/go-cpio/testdata/etc/hosts
generated
vendored
@ -1,2 +0,0 @@
|
||||
127.0.0.1 localhost
|
||||
::1 localhost
|
4
vendor/github.com/cavaliercoder/go-cpio/testdata/gophers.txt
generated
vendored
4
vendor/github.com/cavaliercoder/go-cpio/testdata/gophers.txt
generated
vendored
@ -1,4 +0,0 @@
|
||||
Gopher names:
|
||||
George
|
||||
Geoffrey
|
||||
Gonzo
|
1
vendor/github.com/cavaliercoder/go-cpio/testdata/readme.txt
generated
vendored
1
vendor/github.com/cavaliercoder/go-cpio/testdata/readme.txt
generated
vendored
@ -1 +0,0 @@
|
||||
This archive contains some text files.
|
BIN
vendor/github.com/cavaliercoder/go-cpio/testdata/test_odc.cpio
generated
vendored
BIN
vendor/github.com/cavaliercoder/go-cpio/testdata/test_odc.cpio
generated
vendored
Binary file not shown.
BIN
vendor/github.com/cavaliercoder/go-cpio/testdata/test_svr4.cpio
generated
vendored
BIN
vendor/github.com/cavaliercoder/go-cpio/testdata/test_svr4.cpio
generated
vendored
Binary file not shown.
BIN
vendor/github.com/cavaliercoder/go-cpio/testdata/test_svr4_crc.cpio
generated
vendored
BIN
vendor/github.com/cavaliercoder/go-cpio/testdata/test_svr4_crc.cpio
generated
vendored
Binary file not shown.
1
vendor/github.com/cavaliercoder/go-cpio/testdata/todo.txt
generated
vendored
1
vendor/github.com/cavaliercoder/go-cpio/testdata/todo.txt
generated
vendored
@ -1 +0,0 @@
|
||||
Get animal handling license.
|
53
vendor/github.com/cavaliercoder/go-cpio/writer_test.go
generated
vendored
53
vendor/github.com/cavaliercoder/go-cpio/writer_test.go
generated
vendored
@ -1,53 +0,0 @@
|
||||
package cpio_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
cpio "github.com/cavaliercoder/go-cpio"
|
||||
)
|
||||
|
||||
func store(w *cpio.Writer, fn string) error {
|
||||
f, err := os.Open(fn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hdr, err := cpio.FileInfoHeader(fi, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := w.WriteHeader(hdr); err != nil {
|
||||
return err
|
||||
}
|
||||
if !fi.IsDir() {
|
||||
if _, err := io.Copy(w, f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func TestWriter(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
w := cpio.NewWriter(&buf)
|
||||
|
||||
if err := store(w, "testdata/etc"); err != nil {
|
||||
t.Fatalf("store: %v", err)
|
||||
}
|
||||
|
||||
if err := store(w, "testdata/etc/hosts"); err != nil {
|
||||
t.Fatalf("store: %v", err)
|
||||
}
|
||||
|
||||
if err := w.Close(); err != nil {
|
||||
t.Fatalf("Close: %v", err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user