MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestComputeJoinAcceptMIC

Function TestComputeJoinAcceptMIC

pkg/crypto/join_messages_test.go:241–295  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

239}
240
241func TestComputeJoinAcceptMIC(t *testing.T) {
242 a := assertions.New(t)
243
244 _, err := ComputeJoinAcceptMIC(types.AES128Key{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 0xff, types.EUI64{0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01}, types.DevNonce{0x02, 0x01}, nil)
245 a.So(err, should.NotBeNil)
246
247 for _, tc := range []struct {
248 Name string
249 Key types.AES128Key
250 Type byte
251 JoinEUI types.EUI64
252 DevNonce types.DevNonce
253 Payload []byte
254 MIC [4]byte
255 }{
256 {
257 Name: "Join-request accept/no CFList",
258 Key: types.AES128Key{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
259 Type: 0xff,
260 JoinEUI: types.EUI64{0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01},
261 DevNonce: types.DevNonce{0x02, 0x01},
262 Payload: []byte{
263 /* MHDR */
264 0b001_000_00,
265 /** JoinNonce **/
266 0x03, 0x02, 0x01,
267 /** NetID **/
268 0x03, 0x02, 0x01,
269 /** DevAddr **/
270 0x04, 0x03, 0x02, 0x01,
271 /** DLSettings **/
272 0x00,
273 /** RxDelay **/
274 0x01,
275 },
276 MIC: [4]byte{0x48, 0xe9, 0xbe, 0x5f},
277 },
278 } {
279 t.Run(tc.Name, func(t *testing.T) {
280 a := assertions.New(t)
281
282 key := deepcopy.Copy(tc.Key).(types.AES128Key)
283 joinEUI := deepcopy.Copy(tc.JoinEUI).(types.EUI64)
284 devNonce := deepcopy.Copy(tc.DevNonce).(types.DevNonce)
285 pld := slices.Clone(tc.Payload)
286 mic, err := ComputeJoinAcceptMIC(key, tc.Type, joinEUI, devNonce, pld)
287 a.So(err, should.BeNil)
288 a.So(mic, should.Equal, tc.MIC)
289 a.So(key, should.Resemble, tc.Key)
290 a.So(joinEUI, should.Equal, tc.JoinEUI)
291 a.So(devNonce, should.Equal, tc.DevNonce)
292 a.So(pld, should.Resemble, tc.Payload)
293 })
294 }
295}

Callers

nothing calls this directly

Calls 5

ComputeJoinAcceptMICFunction · 0.85
NewMethod · 0.65
RunMethod · 0.65
CopyMethod · 0.45
CloneMethod · 0.45

Tested by

no test coverage detected