| Total Complexity | 5 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
|
|
|||
| 2 | |||
| 3 | from collections import OrderedDict |
||
| 4 | from .. import credentials, devices |
||
| 5 | from .tclrequest import TclRequest |
||
| 6 | from .tclresult import EncryptHeaderResult |
||
| 7 | |||
| 8 | class EncryptHeaderRequest(TclRequest): |
||
| 9 | def __init__(self, file_uri): |
||
| 10 | super().__init__() |
||
| 11 | # NOTE: THIS HAS TO BE RUN ON AN ENCSLAVE |
||
| 12 | self.uri = "/encrypt_header.php" |
||
| 13 | self.rawmode = True |
||
| 14 | self.method = "POST" |
||
| 15 | self.file_uri = file_uri |
||
| 16 | |||
| 17 | def get_headers(self): |
||
| 18 | return {"User-Agent": "tcl"} |
||
| 19 | |||
| 20 | def get_params(self): |
||
| 21 | params = OrderedDict() |
||
| 22 | params.update(credentials.get_creds2()) |
||
| 23 | params["address"] = bytes(self.file_uri, "utf-8") |
||
| 24 | return params |
||
| 25 | |||
| 26 | def is_done(self, http_status: int, contents: str) -> bool: |
||
| 27 | # Expect "HTTP 206 Partial Content" response |
||
| 28 | if http_status == 206: |
||
| 29 | self.result = EncryptHeaderResult(contents) |
||
| 30 | self.success = True |
||
| 31 | return True |
||
| 32 | self.error = "HTTP {}".format(http_status) |
||
| 33 | self.success = False |
||
| 34 | return True |
||
| 35 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.