I am a newbie in Python. I try to work with server using Thrift protocol
struct AuthSalt {
1: required i64 client, /* random data */
2: required i64 server, /* data from previous answer */
}
struct AuthRequest {
1: required AuthSalt bootstrap,
2: required string who, /* login */
3: required string signature, /* SHA-1: bootstrap + password + who + bootstrap. */
}
exception NotAuthorisedException {
1: required string description
}
service Bookworm {
AuthResponse Authenticate( 1: required AuthRequest a, 2: required string locale )
throws ( 1: NotAuthorisedException e )
}
I need to create SHA1 digest using this algoritm: bootstrap + password + who + bootstrap.
To create bootstrap I use this:
dig = hashlib.sha1
bootstrap = AuthSalt(0, 0)
dig.update(bootstrap)
dig.update(password + who)
dig.update(bootstrap)
But update method argument type only string and I can't understand how to convert bootstrap to a string.
In C++ this code looks like:
SHA_CTX c;
::SHA1_Init(&c);
::SHA1_Update(&c, &bootstrap, sizeof(bootstrap));
::SHA1_Update(&c, password.c_str(), password.size());
::SHA1_Update(&c, who.c_str(), who.size());
::SHA1_Update(&c, &bootstrap, sizeof(bootstrap));
::SHA1_Final(digest, &c);
Can someone explain how to do it using python?
Thanks in advance!
This is what I was need:
for x in tuple(struct.pack("Q",bootstrap.client)):
dig.update(x)
Convert i64 into 8 bytes and update hash with every byte