|
| 1 | +# Copyright 2024 Marc Mosko |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +import array |
| 17 | +import unittest |
| 18 | + |
| 19 | +from ccnpy.core.HashValue import HashValue |
| 20 | +from ccnpy.core.KeyLink import KeyLink |
| 21 | +from ccnpy.core.Link import Link |
| 22 | +from ccnpy.core.Name import Name |
| 23 | +from ccnpy.core.Tlv import Tlv |
| 24 | + |
| 25 | + |
| 26 | +class KeyLinkTest(unittest.TestCase): |
| 27 | + def test_serialize(self): |
| 28 | + name = Name.from_uri('ccnx:/a/b') |
| 29 | + keyid = HashValue(1, b'ab') |
| 30 | + digest = HashValue(2, b'ABCD') |
| 31 | + link = KeyLink(Link(name=name, keyid=keyid, digest=digest)) |
| 32 | + actual = link.serialize() |
| 33 | + expected = array.array("B", [ |
| 34 | + 0, 14, 0, 36, |
| 35 | + 0, 0, 0, 10, 0, 1, 0, 1, 97, 0, 1, 0, 1, 98, |
| 36 | + 0, 2, 0, 6, 0, 1, 0, 2, 97, 98, |
| 37 | + 0, 3, 0, 8, 0, 2, 0, 4, 65, 66, 67, 68]) |
| 38 | + self.assertEqual(expected, actual) |
| 39 | + |
| 40 | + decoded = KeyLink.parse(Tlv.deserialize(actual)) |
| 41 | + self.assertEqual(link, decoded) |
0 commit comments