cocagne / pysrp

Python implementation of the Secure Remote Password protocol (SRP)
MIT License
113 stars 41 forks source link

Get a UTF-8 string? #54

Open jmarshall9120 opened 1 month ago

jmarshall9120 commented 1 month ago

I'm trying to use this library to do SRP for AWS cognito. I need to pass everything to the API as UTF-8 string. I've noticed its all encoded this way:

def long_to_bytes(n):
    l = list()
    x = 0
    off = 0
    while x != n:
        b = (n >> off) & 0xFF
        l.append( chr(b) )
        x = x | (b << off)
        off += 8
    l.reverse()
    return six.b(''.join(l))

https://github.com/cocagne/pysrp/blob/0414166e9dba63c2677414ace2673ccc24208d23/srp/_pysrp.py#L148

Any idea how to make this optional, so I can encode as necessary for the API?

cocagne commented 1 month ago

I'm afraid I don't quite understand what you're asking. UTF-8 is a binary encoding for string content so when a string is encoded with UTF-8 what you have are raw bytes rather than a string, which is what you want I think. Can you elaborate on what you're trying to do and where you think it's going wrong?

Tom

On Fri, May 24, 2024 at 7:56 AM jmarshall9120 @.***> wrote:

I'm trying to use this library to do SRP for AWS cognito. I need to pass everything to the API as UTF-8 string. I've noticed its all encoded this way:

def long_to_bytes(n): l = list() x = 0 off = 0 while x != n: b = (n >> off) & 0xFF l.append( chr(b) ) x = x | (b << off) off += 8 l.reverse() return six.b(''.join(l))

https://github.com/cocagne/pysrp/blob/0414166e9dba63c2677414ace2673ccc24208d23/srp/_pysrp.py#L148

Any idea how to make this optional, so I can encode as necessary for the API?

— Reply to this email directly, view it on GitHub https://github.com/cocagne/pysrp/issues/54, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANMW7HLDLLISLXZANUVOCDZD42IZAVCNFSM6AAAAABIHRA7LSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGMYTKMZUHAZTCNY . You are receiving this because you are subscribed to this thread.Message ID: @.***>