I'm a C# developer and I'm implementing some code in C# thats based around byte operations (decryption stuff). I've found a python repo that does some of the things i need to do, but I'm having trouble understanding some of the code used in the script since I'm not well versed in Python.
The operation goes as follows: A method with a parameter of type Callable[[bytes], bytes] gets called with a parameter that's (unless I'm mistaken) also a bytes. what does that represent and more importantly: how to replicate in C#?
from Crypto.Cipher import AES
import io
def do_the_thing(some_bytes: bytes,
interesting_var: Callable[[bytes], bytes],
more_bytes: bytes
other_data: Optional[bytes] = None) -> dict:
cipher = AES.new(some_bytes, AES.MODE_CBC, IV=b'\x00' * 16)
plaintext = cipher.decrypt(more_bytes)
pstream = io.BytesIO(plaintext)
uid = pstream.read(uid_length)
""" and now the line I'm confused about: """
result = interesting_var(uid)
Any insight into what's going on here would be much appreciated!
CodePudding user response:
f: Callable[[bytes], bytes]
means that f
is a function (a callable) that expects a single argument of the type bytes
(that is what [bytes]
stands for) and returns bytes
.
https://docs.python.org/3/library/typing.html#typing.Callable