| 203 | } |
| 204 | |
| 205 | func demonstrateAllByteValues(client cycletls.CycleTLS) { |
| 206 | // Create data with all possible byte values |
| 207 | allBytesData := make([]byte, 256) |
| 208 | for i := range allBytesData { |
| 209 | allBytesData[i] = byte(i) |
| 210 | } |
| 211 | |
| 212 | originalHasher := sha256.New() |
| 213 | originalHasher.Write(allBytesData) |
| 214 | originalHash := hex.EncodeToString(originalHasher.Sum(nil)) |
| 215 | |
| 216 | // Upload using BodyBytes |
| 217 | response, err := client.Do("https://httpbin.org/post", cycletls.Options{ |
| 218 | BodyBytes: allBytesData, |
| 219 | Headers: map[string]string{ |
| 220 | "Content-Type": "application/octet-stream", |
| 221 | }, |
| 222 | }, "POST") |
| 223 | |
| 224 | if err != nil { |
| 225 | log.Printf("❌ Upload failed: %v", err) |
| 226 | return |
| 227 | } |
| 228 | |
| 229 | // Parse and verify all byte values are preserved |
| 230 | var respData map[string]interface{} |
| 231 | if err := json.Unmarshal([]byte(response.Body), &respData); err != nil { |
| 232 | log.Printf("❌ Failed to parse response: %v", err) |
| 233 | return |
| 234 | } |
| 235 | |
| 236 | if dataField, ok := respData["data"].(string); ok && dataField != "" { |
| 237 | decodedData, err := base64.StdEncoding.DecodeString(dataField) |
| 238 | if err != nil { |
| 239 | log.Printf("❌ Failed to decode base64 data: %v", err) |
| 240 | return |
| 241 | } |
| 242 | |
| 243 | receivedHasher := sha256.New() |
| 244 | receivedHasher.Write(decodedData) |
| 245 | receivedHash := hex.EncodeToString(receivedHasher.Sum(nil)) |
| 246 | |
| 247 | fmt.Printf(" Original hash: %s\n", originalHash) |
| 248 | fmt.Printf(" Received hash: %s\n", receivedHash) |
| 249 | fmt.Printf(" ✅ All 256 byte values preserved: %t\n", originalHash == receivedHash) |
| 250 | |
| 251 | // Verify each byte value individually |
| 252 | if len(decodedData) == 256 { |
| 253 | allCorrect := true |
| 254 | for i := 0; i < 256; i++ { |
| 255 | if decodedData[i] != byte(i) { |
| 256 | fmt.Printf(" ❌ Byte corruption at position %d: expected %d, got %d\n", i, i, decodedData[i]) |
| 257 | allCorrect = false |
| 258 | break |
| 259 | } |
| 260 | } |
| 261 | if allCorrect { |
| 262 | fmt.Println(" ✅ Individual byte verification passed") |