Callable[[bytes], bytes]定义了什么?用bytes对象调用变量返回什么?



我是一名c#开发人员,我正在c#中实现一些基于字节操作(解密内容)的代码。我找到了一个python repo,它做了一些我需要做的事情,但我在理解脚本中使用的一些代码时遇到了麻烦,因为我不太精通python。

操作如下:一个参数类型为Callable[[bytes], bytes]的方法被调用的参数(除非我搞错了)也是一个字节。这代表了什么,更重要的是:如何在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)

任何关于这里发生的事情的见解将非常感激!

f: Callable[[bytes], bytes]表示f是一个函数(一个可调用的函数),它需要一个类型为bytes(即[bytes]所代表的)的参数,并返回bytes

https://docs.python.org/3/library/typing.html typing.Callable

最新更新