# # Copyright (C) 2007-2008 OpenWrt.org # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. # include $(TOPDIR)/rules.mk PKG_NAME:=bzip2 PKG_VERSION:=1.0.6 PKG_RELEASE:=2 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://www.bzip.org/$(PKG_VERSION) PKG_MD5SUM:=00b516f4704d4a7cb50a1d97e6e8e15b PKG_MAINTAINER:=Steven Barth PKG_LICENSE:=BZIP2 PKG_LICENSE_FILES:=LICENSE include $(INCLUDE_DIR)/host-build.mk include $(INCLUDE_DIR)/package.mk define Package/bzip2/Default SUBMENU:=Compression URL:=http://www.bzip.org/ endef define Package/libbz2 $(call Package/bzip2/Default) SECTION:=libs CATEGORY:=Libraries DEPENDS:= TITLE:=bzip2 library. endef define Package/libbz2/description bzip2 is a freely available, patent free, high-quality data compressor. This packages provides libbz2 library. endef define Package/bzip2 $(call Package/bzip2/Default) SECTION:=utils CATEGORY:=Utilities DEPENDS:=+libbz2 TITLE:=bzip2 is a compression utility. endef define Package/bzip2/description bzip2 is a freely available, patent free, high-quality data compressor. This package provides the binary. endef TARGET_CFLAGS += \ $(FPIC) \ $(TARGET_LDFLAGS) CONFIGURE_ARGS += --prefix=/usr MAKE_FLAGS += \ -f Makefile-libbz2_so \ CFLAGS="$(TARGET_CFLAGS)" \ all define Build/InstallDev $(INSTALL_DIR) $(1)/usr/include $(CP) $(PKG_BUILD_DIR)/bzlib.h $(1)/usr/include/ $(INSTALL_DIR) $(1)/usr/lib $(CP) $(PKG_BUILD_DIR)/libbz2.so.$(PKG_VERSION) $(1)/usr/lib/ $(LN) libbz2.so.$(PKG_VERSION) $(1)/usr/lib/libbz2.so.1.0 $(LN) libbz2.so.$(PKG_VERSION) $(1)/usr/lib/libbz2.so endef define Package/libbz2/install $(INSTALL_DIR) $(1)/usr/lib/ $(CP) $(PKG_BUILD_DIR)/libbz2.so.$(PKG_VERSION) $(1)/usr/lib/ $(LN) libbz2.so.$(PKG_VERSION) $(1)/usr/lib/libbz2.so.1.0 endef define Package/bzip2/install $(INSTALL_DIR) $(1)/usr/bin/ $(INSTALL_BIN) $(PKG_BUILD_DIR)/bzip2-shared $(1)/usr/bin/bzip2 endef HOST_CFLAGS += \ $(FPIC) \ $(HOST_LDFLAGS) HOST_MAKE_FLAGS+= \ -f Makefile-libbz2_so \ CFLAGS="$(HOST_CFLAGS)" \ all HOST_CONFIGURE_ARGS+= \ --prefix=$(STAGING_DIR_HOST) define Host/Install $(INSTALL_DIR) $(STAGING_DIR_HOST)/bin/ $(STAGING_DIR_HOST)/usr/lib $(MAKE) -C $(HOST_BUILD_DIR) PREFIX=$(STAGING_DIR_HOST)/usr/ install $(CP) $(HOST_BUILD_DIR)/libbz2.so* $(STAGING_DIR_HOST)/usr/lib/ $(CP) $(HOST_BUILD_DIR)/libbz2.so.1.0 $(STAGING_DIR_HOST)/usr/lib/libbz2.so endef $(eval $(call HostBuild)) $(eval $(call BuildPackage,libbz2)) $(eval $(call BuildPackage,bzip2)) ='10' name='q' value=''/>
path: root/tests/hazmat/primitives/test_hmac.py
blob: 992bcb1aa3dde3fdb09df1efd42e6df0927274e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

import pretend

import pytest

import six

from cryptography.exceptions import AlreadyFinalized
from cryptography.hazmat.primitives import hashes, hmac

from .utils import generate_base_hmac_test


class TestHMAC(object):
    test_copy = generate_base_hmac_test(
        hashes.MD5(),
        only_if=lambda backend: backend.hash_supported(hashes.MD5),
        skip_message="Does not support MD5",
    )

    def test_hmac_reject_unicode(self, backend):
        h = hmac.HMAC(b"mykey", hashes.SHA1(), backend=backend)
        with pytest.raises(TypeError):
            h.update(six.u("\u00FC"))

    def test_copy_backend_object(self):
        pretend_hmac = pretend.stub()
        pretend_backend = pretend.stub(hmacs=pretend_hmac)
        copied_ctx = pretend.stub()
        pretend_ctx = pretend.stub(copy=lambda: copied_ctx)
        h = hmac.HMAC(b"key", hashes.SHA1(), backend=pretend_backend,
                      ctx=pretend_ctx)
        assert h._backend is pretend_backend
        assert h.copy()._backend is pretend_backend

    def test_hmac_algorithm_instance(self, backend):
        with pytest.raises(TypeError):
            hmac.HMAC(b"key", hashes.SHA1, backend=backend)

    def test_raises_after_finalize(self, backend):
        h = hmac.HMAC(b"key", hashes.SHA1(), backend=backend)
        h.finalize()

        with pytest.raises(AlreadyFinalized):
            h.update(b"foo")

        with pytest.raises(AlreadyFinalized):
            h.copy()

        with pytest.raises(AlreadyFinalized):
            h.finalize()