Skip to content

Commit

Permalink
Added a regression test for strings generated by the old protect_stri…
Browse files Browse the repository at this point in the history
…ng() implementation
  • Loading branch information
d0 committed Mar 3, 2016
1 parent 36970a2 commit 82e9248
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion npa/src/opensc
Submodule opensc updated 245 files
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class TestCryptoUtils(unittest.TestCase):
def setUp(self):
self.teststring = "DEADBEEFistatsyksdvhwohfwoehcowc8hw8rogfq8whv75tsgohsav8wress"
self.testpass = "SomeRandomPassphrase"
# The following string was generated using the proteced string method and
# is used as regression test.
# The data generated by protect_string should actually consist of
# printable characters only but that would break backwards
# compatibility with the (buggy) legacy implementation
self.protectedTestString = "2470356b322424504f63775949487224ffa330e33b2d76b82e91a4c88ff722414d3522bcbdb8a4a45cd7c61963b52825e1361354d5b5efbcfeabfb66fa3f97dfecd5e57617b8e0172017785f4001e9653366363763323639363965313261386363623738326435326639653563633339".decode('hex')

def test_padding(self):
padded = append_padding(16, self.teststring)
Expand All @@ -36,6 +42,9 @@ def test_protect_string(self):
unprotectedString = read_protected_string(protectedString, self.testpass)
self.assertEqual(self.teststring, unprotectedString)

def test_unprotect_string(self):
unprotectedString = read_protected_string(self.protectedTestString, self.testpass)
self.assertEqual(unprotectedString, self.teststring)

if __name__ == "__main__":
unittest.main()

0 comments on commit 82e9248

Please sign in to comment.