diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-10-03 14:50:48 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-10-03 14:50:48 -0500 |
commit | b181f2a57d57caaa6e53e193e88002a15e284fd0 (patch) | |
tree | 2c9fd5cc1f8d0219483d97b9fec2a699ec458f37 | |
parent | f80e28767f60f90b6f0caa0c0dca17accf99ce71 (diff) | |
download | cryptography-b181f2a57d57caaa6e53e193e88002a15e284fd0.tar.gz cryptography-b181f2a57d57caaa6e53e193e88002a15e284fd0.tar.bz2 cryptography-b181f2a57d57caaa6e53e193e88002a15e284fd0.zip |
add the missing file. i are senior dvlpr
-rw-r--r-- | cryptography/hazmat/backends/openssl/utils.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/cryptography/hazmat/backends/openssl/utils.py b/cryptography/hazmat/backends/openssl/utils.py new file mode 100644 index 00000000..408b6146 --- /dev/null +++ b/cryptography/hazmat/backends/openssl/utils.py @@ -0,0 +1,35 @@ +# 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 six + + +def _truncate_digest(digest, order_bits): + digest_len = len(digest) + + if 8 * digest_len > order_bits: + digest_len = (order_bits + 7) // 8 + digest = digest[:digest_len] + + if 8 * digest_len > order_bits: + rshift = 8 - (order_bits & 0x7) + assert rshift > 0 and rshift < 8 + + mask = 0xFF >> rshift << rshift + + # Set the bottom rshift bits to 0 + digest = digest[:-1] + six.int2byte(six.indexbytes(digest, -1) & mask) + + return digest |