File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ package cryptography
2+
3+ import (
4+ "crypto/sha256"
5+ "fmt"
6+ )
7+
8+ func CalculateChecksum (data []byte ) string {
9+ sum := sha256 .Sum224 (data )
10+
11+ return fmt .Sprintf ("%x" , sum )
12+ }
Original file line number Diff line number Diff line change 1+ package cryptography
2+
3+ import (
4+ "strings"
5+ "testing"
6+ )
7+
8+ func TestSum224 (t * testing.T ) {
9+ msg := "ABCD"
10+ res := CalculateChecksum ([]byte (msg ))
11+
12+ if ! strings .HasSuffix (res , "60b6" ) {
13+ t .Error ("Expected input to generate another checksum..." )
14+ }
15+ }
Original file line number Diff line number Diff line change @@ -8,13 +8,17 @@ import (
88
99 "github.com/charmbracelet/log"
1010 "github.com/gofiber/fiber/v2"
11+ "github.com/unhanded/txp/internal/cryptography"
1112)
1213
1314func placeContext (c * fiber.Ctx , targetDir string ) error {
15+ b := c .Body ()
16+ sum := cryptography .CalculateChecksum (b )
1417 ctx := map [string ]any {
1518 "fromIP" : c .IP (),
1619 "timestamp" : time .Now ().Format ("2006-01-02 15:04:05 UTC" ),
1720 "method" : c .Method (),
21+ "sha224" : sum ,
1822 }
1923
2024 b , jsonErr := json .Marshal (ctx )
You can’t perform that action at this time.
0 commit comments