# -*- coding: utf-8 -*-
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
from . import testutils
if __name__ == "__main__":
import pkg5unittest
import six
import unittest
try:
except ImportError:
"""A class tests the sha512_t module."""
if not sha512_supported:
return
# The expected values are from the examples:
# Test SHA512/256
# Test hexdigest()
a.update(b"abc")
expected = "53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23"
a = sha512_t.SHA512_t(b"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu")
expected = "3928e184fb8690f840da3988121d31be65cb9d3ef83ee6146feac861e19b563a"
# Test the length of the output of hexdigest()
# Test digest()
a.update(b"abc")
expected = b"S\x04\x8e&\x81\x94\x1e\xf9\x9b.)\xb7kL}\xab\xe4\xc2\xd0\xc64\xfcmF\xe0\xe2\xf11\x07\xe7\xaf#"
# Test the length of the output of digest()
# Test update()
a.update(b"bc")
expected = "53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23"
a.hexdigest()
a.digest()
a.update(b"b")
a.hexdigest()
a.update(b"c")
# Test hash_size
# Test SHA512/224
a.update(b"abc")
expected = "4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa"
a = sha512_t.SHA512_t(b"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", t=224)
expected = "23fec5bb94d60b23308192640b0c453335d664734fe40e7268674af9"
# Test positional arguments
expected = "4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa"
# Test keyword arguments
expected = "4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa"
# Test scalability
for i in range(1000000):
a.update(b"abc")
a.hexdigest()
# Test bad input
# We allow unicode in Python 2 as hashlib does
expected = "53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23"
# Test special unicode character
a.hexdigest()
a.update("ρ⑂☂♄øη")
a.hexdigest()
else:
# We don't allow unicode in Python 3 as hashlib does
if __name__ == "__main__":