Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
5ed033b5
Kaydet (Commit)
5ed033b5
authored
Tem 09, 2007
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Change hashlib to return bytes from digest() instead of str8.
üst
867bcbcd
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
29 deletions
+32
-29
test_hashlib.py
Lib/test/test_hashlib.py
+22
-19
uuid.py
Lib/uuid.py
+2
-2
_hashopenssl.c
Modules/_hashopenssl.c
+2
-2
sha256module.c
Modules/sha256module.c
+3
-3
sha512module.c
Modules/sha512module.c
+3
-3
No files found.
Lib/test/test_hashlib.py
Dosyayı görüntüle @
5ed033b5
...
@@ -12,12 +12,12 @@ from test import test_support
...
@@ -12,12 +12,12 @@ from test import test_support
def
hexstr
(
s
):
def
hexstr
(
s
):
import
string
assert
isinstance
(
s
,
bytes
),
repr
(
s
)
h
=
string
.
hexdigits
h
=
b
"0123456789abcdef"
r
=
''
r
=
b
''
for
c
in
s
:
for
i
in
s
:
i
=
ord
(
c
)
r
.
append
(
h
[(
i
>>
4
)
&
0xF
]
)
r
=
r
+
h
[(
i
>>
4
)
&
0xF
]
+
h
[
i
&
0xF
]
r
.
append
(
h
[
i
&
0xF
])
return
r
return
r
...
@@ -37,7 +37,8 @@ class HashLibTestCase(unittest.TestCase):
...
@@ -37,7 +37,8 @@ class HashLibTestCase(unittest.TestCase):
def
test_hexdigest
(
self
):
def
test_hexdigest
(
self
):
for
name
in
self
.
supported_hash_names
:
for
name
in
self
.
supported_hash_names
:
h
=
hashlib
.
new
(
name
)
h
=
hashlib
.
new
(
name
)
self
.
assert_
(
hexstr
(
h
.
digest
())
==
h
.
hexdigest
())
assert
isinstance
(
h
.
digest
(),
bytes
),
name
self
.
assertEqual
(
hexstr
(
h
.
digest
()),
h
.
hexdigest
())
def
test_large_update
(
self
):
def
test_large_update
(
self
):
...
@@ -66,14 +67,15 @@ class HashLibTestCase(unittest.TestCase):
...
@@ -66,14 +67,15 @@ class HashLibTestCase(unittest.TestCase):
def
test_case_md5_0
(
self
):
def
test_case_md5_0
(
self
):
self
.
check
(
'md5'
,
''
,
'd41d8cd98f00b204e9800998ecf8427e'
)
self
.
check
(
'md5'
,
b
''
,
b
'd41d8cd98f00b204e9800998ecf8427e'
)
def
test_case_md5_1
(
self
):
def
test_case_md5_1
(
self
):
self
.
check
(
'md5'
,
'abc'
,
'900150983cd24fb0d6963f7d28e17f72'
)
self
.
check
(
'md5'
,
b
'abc'
,
b
'900150983cd24fb0d6963f7d28e17f72'
)
def
test_case_md5_2
(
self
):
def
test_case_md5_2
(
self
):
self
.
check
(
'md5'
,
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
,
self
.
check
(
'md5'
,
'd174ab98d277d9f5a5611c2c9f419d9f'
)
b
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
,
b
'd174ab98d277d9f5a5611c2c9f419d9f'
)
# use the three examples from Federal Information Processing Standards
# use the three examples from Federal Information Processing Standards
...
@@ -81,20 +83,21 @@ class HashLibTestCase(unittest.TestCase):
...
@@ -81,20 +83,21 @@ class HashLibTestCase(unittest.TestCase):
# http://www.itl.nist.gov/div897/pubs/fip180-1.htm
# http://www.itl.nist.gov/div897/pubs/fip180-1.htm
def
test_case_sha1_0
(
self
):
def
test_case_sha1_0
(
self
):
self
.
check
(
'sha1'
,
""
,
self
.
check
(
'sha1'
,
b
""
,
"da39a3ee5e6b4b0d3255bfef95601890afd80709"
)
b
"da39a3ee5e6b4b0d3255bfef95601890afd80709"
)
def
test_case_sha1_1
(
self
):
def
test_case_sha1_1
(
self
):
self
.
check
(
'sha1'
,
"abc"
,
self
.
check
(
'sha1'
,
b
"abc"
,
"a9993e364706816aba3e25717850c26c9cd0d89d"
)
b
"a9993e364706816aba3e25717850c26c9cd0d89d"
)
def
test_case_sha1_2
(
self
):
def
test_case_sha1_2
(
self
):
self
.
check
(
'sha1'
,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
self
.
check
(
'sha1'
,
"84983e441c3bd26ebaae4aa1f95129e5e54670f1"
)
b
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
b
"84983e441c3bd26ebaae4aa1f95129e5e54670f1"
)
def
test_case_sha1_3
(
self
):
def
test_case_sha1_3
(
self
):
self
.
check
(
'sha1'
,
"a"
*
1000000
,
self
.
check
(
'sha1'
,
b
"a"
*
1000000
,
"34aa973cd4c4daa4f61eeb2bdbad27316534016f"
)
b
"34aa973cd4c4daa4f61eeb2bdbad27316534016f"
)
# use the examples from Federal Information Processing Standards
# use the examples from Federal Information Processing Standards
...
...
Lib/uuid.py
Dosyayı görüntüle @
5ed033b5
...
@@ -528,7 +528,7 @@ def uuid3(namespace, name):
...
@@ -528,7 +528,7 @@ def uuid3(namespace, name):
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
from
hashlib
import
md5
from
hashlib
import
md5
hash
=
md5
(
namespace
.
bytes
+
bytes
(
name
,
"utf-8"
))
.
digest
()
hash
=
md5
(
namespace
.
bytes
+
bytes
(
name
,
"utf-8"
))
.
digest
()
return
UUID
(
bytes
=
bytes_
(
hash
[:
16
])
,
version
=
3
)
return
UUID
(
bytes
=
hash
[:
16
]
,
version
=
3
)
def
uuid4
():
def
uuid4
():
"""Generate a random UUID."""
"""Generate a random UUID."""
...
@@ -551,7 +551,7 @@ def uuid5(namespace, name):
...
@@ -551,7 +551,7 @@ def uuid5(namespace, name):
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
from
hashlib
import
sha1
from
hashlib
import
sha1
hash
=
sha1
(
namespace
.
bytes
+
bytes
(
name
,
"utf-8"
))
.
digest
()
hash
=
sha1
(
namespace
.
bytes
+
bytes
(
name
,
"utf-8"
))
.
digest
()
return
UUID
(
bytes
=
bytes_
(
hash
[:
16
])
,
version
=
5
)
return
UUID
(
bytes
=
hash
[:
16
]
,
version
=
5
)
# The following standard UUIDs are for use with uuid3() or uuid5().
# The following standard UUIDs are for use with uuid3() or uuid5().
...
...
Modules/_hashopenssl.c
Dosyayı görüntüle @
5ed033b5
...
@@ -103,7 +103,7 @@ EVP_digest(EVPobject *self, PyObject *unused)
...
@@ -103,7 +103,7 @@ EVP_digest(EVPobject *self, PyObject *unused)
digest_size
=
EVP_MD_CTX_size
(
&
temp_ctx
);
digest_size
=
EVP_MD_CTX_size
(
&
temp_ctx
);
EVP_DigestFinal
(
&
temp_ctx
,
digest
,
NULL
);
EVP_DigestFinal
(
&
temp_ctx
,
digest
,
NULL
);
retval
=
Py
String
_FromStringAndSize
((
const
char
*
)
digest
,
digest_size
);
retval
=
Py
Bytes
_FromStringAndSize
((
const
char
*
)
digest
,
digest_size
);
EVP_MD_CTX_cleanup
(
&
temp_ctx
);
EVP_MD_CTX_cleanup
(
&
temp_ctx
);
return
retval
;
return
retval
;
}
}
...
@@ -133,7 +133,7 @@ EVP_hexdigest(EVPobject *self, PyObject *unused)
...
@@ -133,7 +133,7 @@ EVP_hexdigest(EVPobject *self, PyObject *unused)
retval
=
PyString_FromStringAndSize
(
NULL
,
digest_size
*
2
);
retval
=
PyString_FromStringAndSize
(
NULL
,
digest_size
*
2
);
if
(
!
retval
)
if
(
!
retval
)
return
NULL
;
return
NULL
;
hex_digest
=
PyString_A
sString
(
retval
);
hex_digest
=
PyString_A
S_STRING
(
retval
);
if
(
!
hex_digest
)
{
if
(
!
hex_digest
)
{
Py_DECREF
(
retval
);
Py_DECREF
(
retval
);
return
NULL
;
return
NULL
;
...
...
Modules/sha256module.c
Dosyayı görüntüle @
5ed033b5
...
@@ -432,7 +432,7 @@ SHA256_digest(SHAobject *self, PyObject *unused)
...
@@ -432,7 +432,7 @@ SHA256_digest(SHAobject *self, PyObject *unused)
SHAcopy
(
self
,
&
temp
);
SHAcopy
(
self
,
&
temp
);
sha_final
(
digest
,
&
temp
);
sha_final
(
digest
,
&
temp
);
return
Py
String
_FromStringAndSize
((
const
char
*
)
digest
,
self
->
digestsize
);
return
Py
Bytes
_FromStringAndSize
((
const
char
*
)
digest
,
self
->
digestsize
);
}
}
PyDoc_STRVAR
(
SHA256_hexdigest__doc__
,
PyDoc_STRVAR
(
SHA256_hexdigest__doc__
,
...
@@ -510,9 +510,9 @@ static PyObject *
...
@@ -510,9 +510,9 @@ static PyObject *
SHA256_get_name
(
PyObject
*
self
,
void
*
closure
)
SHA256_get_name
(
PyObject
*
self
,
void
*
closure
)
{
{
if
(((
SHAobject
*
)
self
)
->
digestsize
==
32
)
if
(((
SHAobject
*
)
self
)
->
digestsize
==
32
)
return
Py
String
_FromStringAndSize
(
"SHA256"
,
6
);
return
Py
Unicode
_FromStringAndSize
(
"SHA256"
,
6
);
else
else
return
Py
String
_FromStringAndSize
(
"SHA224"
,
6
);
return
Py
Unicode
_FromStringAndSize
(
"SHA224"
,
6
);
}
}
static
PyGetSetDef
SHA_getseters
[]
=
{
static
PyGetSetDef
SHA_getseters
[]
=
{
...
...
Modules/sha512module.c
Dosyayı görüntüle @
5ed033b5
...
@@ -498,7 +498,7 @@ SHA512_digest(SHAobject *self, PyObject *unused)
...
@@ -498,7 +498,7 @@ SHA512_digest(SHAobject *self, PyObject *unused)
SHAcopy
(
self
,
&
temp
);
SHAcopy
(
self
,
&
temp
);
sha512_final
(
digest
,
&
temp
);
sha512_final
(
digest
,
&
temp
);
return
Py
String
_FromStringAndSize
((
const
char
*
)
digest
,
self
->
digestsize
);
return
Py
Bytes
_FromStringAndSize
((
const
char
*
)
digest
,
self
->
digestsize
);
}
}
PyDoc_STRVAR
(
SHA512_hexdigest__doc__
,
PyDoc_STRVAR
(
SHA512_hexdigest__doc__
,
...
@@ -576,9 +576,9 @@ static PyObject *
...
@@ -576,9 +576,9 @@ static PyObject *
SHA512_get_name
(
PyObject
*
self
,
void
*
closure
)
SHA512_get_name
(
PyObject
*
self
,
void
*
closure
)
{
{
if
(((
SHAobject
*
)
self
)
->
digestsize
==
64
)
if
(((
SHAobject
*
)
self
)
->
digestsize
==
64
)
return
Py
String
_FromStringAndSize
(
"SHA512"
,
6
);
return
Py
Unicode
_FromStringAndSize
(
"SHA512"
,
6
);
else
else
return
Py
String
_FromStringAndSize
(
"SHA384"
,
6
);
return
Py
Unicode
_FromStringAndSize
(
"SHA384"
,
6
);
}
}
static
PyGetSetDef
SHA_getseters
[]
=
{
static
PyGetSetDef
SHA_getseters
[]
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment