very bad demo code

This commit is contained in:
Joe Kralicky 2025-02-18 01:33:15 +00:00
parent b4aa275403
commit d588135b3a
No known key found for this signature in database
GPG key ID: 75C4875F34A9FB79
30 changed files with 1308 additions and 248 deletions

View file

@ -1,9 +1,6 @@
package envoy
import (
"bytes"
"crypto/sha256"
"encoding/hex"
"fmt"
"hash"
"io"
@ -13,8 +10,6 @@ import (
"sync"
"github.com/rs/zerolog/log"
"github.com/pomerium/pomerium/pkg/envoy/files"
)
const (
@ -76,34 +71,6 @@ func Extract() (fullEnvoyPath string, err error) {
return setupFullEnvoyPath, setupErr
}
func extract(dstName string) (err error) {
checksum, err := hex.DecodeString(strings.Fields(files.Checksum())[0])
if err != nil {
return fmt.Errorf("checksum %s: %w", files.Checksum(), err)
}
hr := &hashReader{
Hash: sha256.New(),
r: bytes.NewReader(files.Binary()),
}
dst, err := os.OpenFile(dstName, os.O_CREATE|os.O_WRONLY, ownerRX)
if err != nil {
return err
}
defer func() { err = dst.Close() }()
if _, err = io.Copy(dst, io.LimitReader(hr, maxExpandedEnvoySize)); err != nil {
return err
}
sum := hr.Sum(nil)
if !bytes.Equal(sum, checksum) {
return fmt.Errorf("expected %x, got %x checksum", checksum, sum)
}
return nil
}
func cleanTempDir(tmpDir string) {
d, err := os.Open(tmpDir)
if err != nil {