diff --git a/lib/crypto/tunnel.go b/lib/crypto/tunnel.go index 8db154c..4ce2539 100644 --- a/lib/crypto/tunnel.go +++ b/lib/crypto/tunnel.go @@ -5,7 +5,7 @@ import ( "crypto/cipher" ) -type TunnelData [1024]byte +type TunnelData [1028]byte // A symetric key for encrypting tunnel messages type TunnelKey [32]byte diff --git a/lib/tunnel/message.go b/lib/tunnel/message.go index 62e9e60..734e957 100644 --- a/lib/tunnel/message.go +++ b/lib/tunnel/message.go @@ -7,14 +7,33 @@ import ( type TunnelID uint32 -// data sent down a tunnel -type TunnelMessage crypto.TunnelData +type EncryptedTunnelMessage crypto.TunnelData -func (tm TunnelMessage) ID() (tid TunnelID) { +func (tm EncryptedTunnelMessage) ID() (tid TunnelID) { tid = TunnelID(binary.BigEndian.Uint32(tm[:4])) return } -func (tm TunnelMessage) IV() crypto.TunnelIV { +func (tm EncryptedTunnelMessage) IV() crypto.TunnelIV { return tm[4:20] } + +func (tm EncryptedTunnelMessage) Data() crypto.TunnelIV { + return tm[24:] +} + +type DecryptedTunnelMessage [1028]byte + +func (decrypted_tunnel_message DecryptedTunnelMessage) ID() TunnelID { + return TunnelID(binary.BigEndian.Uint32( + decrypted_tunnel_message[:4], + )) +} + +func (decrypted_tunnel_message DecryptedTunnelMessage) IV() crypto.TunnelIV { + return decrypted_tunnel_message[4:20] +} + +func (decrypted_tunnel_message DecryptedTunnelMessage) Checksum() crypto.TunnelIV { + return decrypted_tunnel_message[24:28] +} diff --git a/lib/tunnel/message_test.go b/lib/tunnel/message_test.go new file mode 100644 index 0000000..b7d16d3 --- /dev/null +++ b/lib/tunnel/message_test.go @@ -0,0 +1,6 @@ +package tunnel + +import ( +//"github.com/stretchr/testify/assert" +//"testing" +)