def encrypt(self, orig_pkt, assoclen=None):
        """encrypt a MACsec frame for this Secure Association"""
        hdr = copy.deepcopy(orig_pkt)
        del hdr[MACsec].payload
        del hdr[MACsec].type
        pktlen = len(orig_pkt)
        if self.send_sci:
            hdrlen = NOSCI_LEN + SCI_LEN
        else:
            hdrlen = NOSCI_LEN
        if assoclen is None or not self.do_encrypt:
            if self.do_encrypt:
                assoclen = hdrlen
            else:
                assoclen = pktlen
        iv = self.make_iv(orig_pkt)
        assoc, pt, _ = MACsecSA.split_pkt(orig_pkt, assoclen)
        encryptor = Cipher(
            algorithms.AES(self.key),
            modes.GCM(iv),
            backend=default_backend()
        ).encryptor()
        encryptor.authenticate_additional_data(assoc)
        ct = encryptor.update(pt) + encryptor.finalize()
        hdr[MACsec].payload = Raw(assoc[hdrlen:assoclen] + ct + encryptor.tag)
        return hdr
def encrypt ( self , orig_pkt , assoclen = None ) : hdr = copy . deepcopy ( orig_pkt ) del hdr [ MACsec ] . payload del hdr [ MACsec ] . type pktlen = len ( orig_pkt ) if self . send_sci : hdrlen = NOSCI_LEN + SCI_LEN else : hdrlen = NOSCI_LEN if assoclen is None or not self . do_encrypt : if self . do_encrypt : assoclen = hdrlen else : assoclen = pktlen iv = self . make_iv ( orig_pkt ) assoc , pt , _ = MACsecSA . split_pkt ( orig_pkt , assoclen ) encryptor = Cipher ( algorithms . AES ( self . key ) , modes . GCM ( iv ) , backend = default_backend ( ) ) . encryptor ( ) encryptor . authenticate_additional_data ( assoc ) ct = encryptor . update ( pt ) + encryptor . finalize ( ) hdr [ MACsec ] . payload = Raw ( assoc [ hdrlen : assoclen ] + ct + encryptor . tag ) return hdr
encrypt a MACsec frame for this Secure Association