MCPcopy Create free account
hub / github.com/secdev/scapy / Key

Class Key

scapy/libs/rfc3961.py:1251–1416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1249
1250
1251class Key(object):
1252 def __init__(
1253 self,
1254 etype: Union[EncryptionType, int, None] = None,
1255 key: bytes = b"",
1256 cksumtype: Union[ChecksumType, int, None] = None,
1257 ) -> None:
1258 """
1259 Kerberos Key object.
1260
1261 :param etype: the EncryptionType
1262 :param cksumtype: the ChecksumType
1263 :param key: the bytes containing the key bytes for this Key.
1264 """
1265 assert etype or cksumtype, "Provide an etype or a cksumtype !"
1266 assert key, "Provide a key !"
1267 if isinstance(etype, int):
1268 etype = EncryptionType(etype)
1269 if isinstance(cksumtype, int):
1270 cksumtype = ChecksumType(cksumtype)
1271 self.etype = etype
1272 if etype is not None:
1273 try:
1274 self.ep = _enctypes[etype]
1275 except ValueError:
1276 raise ValueError("UNKNOWN/UNIMPLEMENTED etype '%s'" % etype)
1277 if len(key) != self.ep.keysize:
1278 raise ValueError(
1279 "Wrong key length. Got %s. Expected %s"
1280 % (len(key), self.ep.keysize)
1281 )
1282 if cksumtype is None and self.ep.reqcksum in _checksums:
1283 cksumtype = self.ep.reqcksum
1284 self.cksumtype = cksumtype
1285 if cksumtype is not None:
1286 try:
1287 self.cp = _checksums[cksumtype]
1288 except ValueError:
1289 raise ValueError("UNKNOWN/UNIMPLEMENTED cksumtype '%s'" % cksumtype)
1290 if self.etype is None and issubclass(self.cp, _SimplifiedChecksum):
1291 self.etype = self.cp.enc.etype # type: ignore
1292 self.key = key
1293
1294 def __repr__(self):
1295 # type: () -> str
1296 if self.etype:
1297 name = self.etype.name
1298 elif self.cksumtype:
1299 name = self.cksumtype.name
1300 else:
1301 return "<Key UNKNOWN>"
1302 return "<Key %s%s>" % (
1303 name,
1304 " (%s octets)" % len(self.key),
1305 )
1306
1307 def encrypt(self, keyusage, plaintext, confounder=None, **kwargs):
1308 # type: (int, bytes, Optional[bytes], **Any) -> bytes

Callers 15

toKeyMethod · 0.90
toKeyMethod · 0.90
_prompt_hashMethod · 0.90
from_cli_argumentsMethod · 0.90
toKeyMethod · 0.90
random_to_keyMethod · 0.85
mit_des_string_to_keyMethod · 0.85
random_to_keyMethod · 0.85
string_to_keyMethod · 0.85
string_to_keyMethod · 0.85
string_to_keyMethod · 0.85
string_to_keyMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected