Skip to content

Commit 3e94cef

Browse files
author
Ivan Nikolchev
committed
Deprecate methods which were replaced by calc_key
1 parent 4c609bc commit 3e94cef

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

tlslite/mathtls.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .constants import CipherSuite
1414
from .utils import tlshashlib as hashlib
1515
from .utils import tlshmac as hmac
16+
from .utils.deprecations import deprecated_method
1617

1718
# 1024, 1536, 2048, 3072, 4096, 6144, and 8192 bit groups
1819
# Formatted to match lines in RFC
@@ -509,6 +510,7 @@ def PRF_SSL(secret, seed, length):
509510
index += 1
510511
return bytes
511512

513+
@deprecated_method("Please use calcKey method instead.")
512514
def calcExtendedMasterSecret(version, cipherSuite, premasterSecret,
513515
handshakeHashes):
514516
"""Derive Extended Master Secret from premaster and handshake msgs"""
@@ -532,6 +534,7 @@ def calcExtendedMasterSecret(version, cipherSuite, premasterSecret,
532534
return masterSecret
533535

534536

537+
@deprecated_method("Please use calcKey method instead.")
535538
def calcMasterSecret(version, cipherSuite, premasterSecret, clientRandom,
536539
serverRandom):
537540
"""Derive Master Secret from premaster secret and random values"""
@@ -556,6 +559,7 @@ def calcMasterSecret(version, cipherSuite, premasterSecret, clientRandom,
556559
raise AssertionError()
557560
return masterSecret
558561

562+
@deprecated_method("Please use calcKey method instead.")
559563
def calcFinished(version, masterSecret, cipherSuite, handshakeHashes,
560564
isClient):
561565
"""Calculate the Handshake protocol Finished value

tlslite/utils/deprecations.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,17 @@ def wrapper(cls):
202202
orig_vars.pop('__weakref__', None)
203203
return metaclass(cls.__name__, cls.__bases__, orig_vars)
204204
return wrapper
205+
206+
def deprecated_method(message):
207+
"""Decorator for deprecating methods.
208+
209+
:param ste message: The message you want to display.
210+
"""
211+
def decorator(func):
212+
@wraps(func)
213+
def wrapper(*args, **kwargs):
214+
warnings.warn("{0} is a deprecated method. {1}".format(func.__name__, message),
215+
DeprecationWarning, stacklevel=2)
216+
return func(*args, **kwargs)
217+
return wrapper
218+
return decorator

unit_tests/test_tlslite_utils_deprecations.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from unittest.mock import call
1818

1919
from tlslite.utils.deprecations import deprecated_params, \
20-
deprecated_attrs, deprecated_class_name
20+
deprecated_attrs, deprecated_class_name, \
21+
deprecated_method
2122

2223
# see https://github.com/pytest-dev/py/issues/110
2324
# preload the list until the list of loaded modules is static
@@ -452,3 +453,19 @@ def method(cls):
452453
self.assertFalse(hasattr(Clazz, "new_cvar"))
453454
with self.assertWarns(DeprecationWarning) as e:
454455
self.assertFalse(hasattr(Clazz, "old_cvar"))
456+
457+
458+
class TestDeprecatedMethods(unittest.TestCase):
459+
def test_deprecated_method(self):
460+
461+
@deprecated_method("Please use foo method instead.")
462+
def test(param):
463+
return param
464+
465+
with self.assertWarns(DeprecationWarning) as e:
466+
r = test("test")
467+
self.assertEqual(r, "test")
468+
469+
self.assertEqual("test is a deprecated method. Please" \
470+
" use foo method instead.",
471+
str(e.warning))

0 commit comments

Comments
 (0)