How to use generate_mac method in localstack

Best Python code snippet using localstack_python

network_unittest.py

Source: network_unittest.py Github

copy

Full Screen

...51 self.assertTrue(IPy.IP(address) in pubnet)52 self.assertTrue(IPy.IP(address) in self.network.network)53 def test_allocate_deallocate_ip(self):54 address = network.allocate_ip(55 "netuser", "project0", utils.generate_mac())56 logging.debug("Was allocated %s" % (address))57 self.assertEqual(True, address in self._get_project_addresses("project0"))58 rv = network.deallocate_ip(address)59 self.assertEqual(False, address in self._get_project_addresses("project0"))60 def test_range_allocation(self):61 address = network.allocate_ip(62 "netuser", "project0", utils.generate_mac())63 secondaddress = network.allocate_ip(64 "netuser", "project1", utils.generate_mac())65 self.assertEqual(True,66 address in self._get_project_addresses("project0"))67 self.assertEqual(True,68 secondaddress in self._get_project_addresses("project1"))69 self.assertEqual(False, address in self._get_project_addresses("project1"))70 rv = network.deallocate_ip(address)71 self.assertEqual(False, address in self._get_project_addresses("project0"))72 rv = network.deallocate_ip(secondaddress)73 self.assertEqual(False,74 secondaddress in self._get_project_addresses("project1"))75 def test_subnet_edge(self):76 secondaddress = network.allocate_ip("netuser", "project0",77 utils.generate_mac())78 for project in range(1,5):79 project_id = "project%s" % (project)80 address = network.allocate_ip(81 "netuser", project_id, utils.generate_mac())82 address2 = network.allocate_ip(83 "netuser", project_id, utils.generate_mac())84 address3 = network.allocate_ip(85 "netuser", project_id, utils.generate_mac())86 self.assertEqual(False,87 address in self._get_project_addresses("project0"))88 self.assertEqual(False,89 address2 in self._get_project_addresses("project0"))90 self.assertEqual(False,91 address3 in self._get_project_addresses("project0"))92 rv = network.deallocate_ip(address)93 rv = network.deallocate_ip(address2)94 rv = network.deallocate_ip(address3)95 rv = network.deallocate_ip(secondaddress)96 def test_too_many_projects(self):97 for i in range(0, 30):98 name = 'toomany-project%s' % i99 self.manager.create_project(name, 'netuser', name)100 address = network.allocate_ip(101 "netuser", name, utils.generate_mac())102 rv = network.deallocate_ip(address)103 self.manager.delete_project(name)104 def _get_project_addresses(self, project_id):105 project_addresses = []106 for addr in network.get_project_network(project_id).list_addresses():107 project_addresses.append(addr)...

Full Screen

Full Screen

main.py

Source: main.py Github

copy

Full Screen

...6SALT = get_random_bytes(16)7def generate_key(password):8 key = PBKDF2(password, SALT, 64, 1000, hmac_hash_module=SHA256)9 return key10def generate_mac(text, key):11 h = HMAC.new(key, digestmod=SHA256)12 h.update(text)13 return h.hexdigest()14def encrypt(plaintext, password, mode):15 key = generate_key(password)16 key1 = key[:32]17 key2 = key[32:]18 if mode == 'ETM':19 cipher = AES.new(key1, AES.MODE_CBC)20 ciphertext = cipher.iv + cipher.encrypt(pad(plaintext, AES.block_size))21 signature = generate_mac(ciphertext, key2)22 return ciphertext + signature.encode()23 if mode == 'EAM':24 signature = generate_mac(plaintext, key2)25 cipher = AES.new(key1, AES.MODE_CBC)26 ciphertext = cipher.iv + cipher.encrypt(pad(plaintext, AES.block_size))27 return ciphertext + signature.encode()28 if mode == 'MTE':29 signature = generate_mac(plaintext, key2)30 plaintext = plaintext + signature.encode()31 cipher = AES.new(key1, AES.MODE_CBC)32 ciphertext = cipher.iv + cipher.encrypt(pad(plaintext, AES.block_size))33 return ciphertext34def decrypt(ciphertext, password, mode):35 key = generate_key(password)36 key1 = key[:32]37 key2 = key[32:]38 if mode == "ETM":39 signature = ciphertext[-64:]40 ciphertext = ciphertext[:-64]41 mac = generate_mac(ciphertext, key2)42 iv = ciphertext[:16]43 ciphertext = ciphertext[16:]44 cipher = AES.new(key1, AES.MODE_CBC, iv)45 plaintext = unpad(cipher.decrypt(ciphertext), AES.block_size)46 return plaintext.decode(), mac.encode() == signature47 if mode == "EAM":48 signature = ciphertext[-64:]49 ciphertext = ciphertext[:-64]50 iv = ciphertext[:16]51 ciphertext = ciphertext[16:]52 cipher = AES.new(key1, AES.MODE_CBC, iv)53 plaintext = unpad(cipher.decrypt(ciphertext), AES.block_size)54 mac = generate_mac(plaintext, key2)55 return plaintext.decode(), mac.encode() == signature56 if mode == "MTE":57 iv = ciphertext[:16]58 ciphertext = ciphertext[16:]59 cipher = AES.new(key1, AES.MODE_CBC, iv)60 plaintext = unpad(cipher.decrypt(ciphertext), AES.block_size)61 signature = plaintext[-64:]62 plaintext = plaintext[0:-64]63 mac = generate_mac(plaintext, key2)64 return plaintext.decode(), mac.encode() == signature65if __name__ == '__main__':66 while True:67 text = str(input("Digite um texto ou nome de um arquivo para ser criptografado: "))68 try:69 file = open(text, "rb")70 text = file.read()71 except:72 text = text.encode()73 password = str(input("Digite uma senha: ")).encode()74 mode = input("Digite um modo de encriptação (ETM, EAM ou MTE): ")75 cypertext = encrypt(text, password, mode)76 plaintext, tag = decrypt(cypertext, password, mode)77 ...

Full Screen

Full Screen

random_name.py

Source: random_name.py Github

copy

Full Screen

1#!/​usr/​bin/​python2#3### 'random_name' Ansible module #############################################4# 2016 - Brian LaShomb <brian.lashomb@target.com>5##############################################################################6DOCUMENTATION = '''7---8module: random_name9short_description: Generates a random MAC Address and/​or modifed for use a VM Name.10'''11EXAMPLES = '''12 - name: Generating random name for VM13 random_name: generate_name=True14'''15RETURN = '''16vm_name:17 description: Name of new VM18 returned: success19 type: string20 sample: "edge_00163e1e52d91"21'''22import random23def randomMAC():24 return [ 0x00, 0x16, 0x3e,25 random.randint(0x00, 0x7f),26 random.randint(0x00, 0xff),27 random.randint(0x00, 0xff) ]28def MACprettyprint(mac):29 return ''.join(map(lambda x: "%02x" % x, mac))30def main():31 '''Generates random MAC address and removes the colons'''32 module = AnsibleModule(33 argument_spec = dict(34 generate_name=dict(default=True, choices=[True, False], type='bool'),35 generate_MAC=dict(default=False, choices=[True, False], type='bool')36 )37 )38 generate_name = module.params['generate_name']39 generate_MAC = module.params['generate_MAC']40 if generate_name == True and generate_MAC == True:41 module.exit_json(changed=True, ansible_facts=dict(vm_name="edge_" + MACprettyprint(randomMAC()), mac_addr=(randomMAC())))42 elif generate_name == True:43 module.exit_json(changed=True, ansible_facts=dict(vm_name="edge_" + MACprettyprint(randomMAC())))44 elif generate_MAC == True:45 module.exit_json(changed=True, ansible_facts=dict(mac_addr=(randomMAC())))46# this is magic, see lib/​ansible/​module_common.py47from ansible.module_utils.basic import *...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation &#8211; Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful