def test_reader(self):
        capture_buf = []

        def do_capture(identity, message_capture_func):
            capture_buf.append(message_capture_func())

        r = pu.Reader(b"secret", do_capture)
        for data in pu._encode_message(b"secret", ['hi'], b'me'):
            self.assertEqual(len(data), r.bytes_needed)
            r.feed(data)

        self.assertEqual(1, len(capture_buf))
        self.assertEqual(['hi'], capture_buf[0])
    def test_reader(self):
        capture_buf = []

        def do_capture(identity, message_capture_func):
            capture_buf.append(message_capture_func())

        r = pu.Reader(b"secret", do_capture)
        for data in pu._encode_message(b"secret", ['hi'], b'me'):
            self.assertEqual(len(data), r.bytes_needed)
            r.feed(data)

        self.assertEqual(1, len(capture_buf))
        self.assertEqual(['hi'], capture_buf[0])
 def test_bad_hmac_reader(self):
     r = pu.Reader(b"secret-2", lambda ident, capture_func: capture_func())
     in_data = b"".join(pu._encode_message(b"secret", ['hi'], b'me'))
     self.assertRaises(pu.BadHmacValueError, r.feed, in_data)
 def test_bad_hmac_reader(self):
     r = pu.Reader(b"secret-2", lambda ident, capture_func: capture_func())
     in_data = b"".join(pu._encode_message(b"secret", ['hi'], b'me'))
     self.assertRaises(pu.BadHmacValueError, r.feed, in_data)