|
19 | 19 | from __future__ import annotations |
20 | 20 |
|
21 | 21 | import datetime |
| 22 | +import decimal |
22 | 23 | from typing import Any, Literal, Optional, TypeVar, Union |
23 | 24 |
|
24 | | -import bigframes.bigquery._googlesql |
25 | 25 | import bigframes.core.col |
26 | 26 | import bigframes.core.expression as ex |
| 27 | +import bigframes.core.googlesql |
27 | 28 | import bigframes.core.sentinels as sentinels |
28 | 29 | import bigframes.operations as ops |
29 | 30 | import bigframes.series as series |
30 | 31 | from bigframes import dtypes |
31 | 32 | from bigframes.operations import googlesql |
32 | 33 |
|
33 | | -T = TypeVar("T", series.Series, bigframes.core.col.Expression) |
34 | | - |
35 | 34 | _DECRYPT_BYTES_OP = googlesql.GoogleSqlScalarOp( |
36 | 35 | "AEAD.DECRYPT_BYTES", |
37 | 36 | args=(googlesql.ArgSpec(), googlesql.ArgSpec(), googlesql.ArgSpec()), |
|
51 | 50 |
|
52 | 51 | def decrypt_bytes( |
53 | 52 | keyset: Union[ |
54 | | - T, |
| 53 | + series.Series, |
55 | 54 | bigframes.core.col.Expression, |
56 | 55 | Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], bytes, dict], |
57 | 56 | ], |
58 | 57 | ciphertext: Union[ |
59 | | - T, |
| 58 | + series.Series, |
60 | 59 | bigframes.core.col.Expression, |
61 | 60 | Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], bytes], |
62 | 61 | ], |
63 | 62 | additional_data: Union[ |
64 | | - T, |
| 63 | + series.Series, |
65 | 64 | bigframes.core.col.Expression, |
66 | 65 | Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], bytes], |
67 | 66 | ], |
68 | | -) -> T: |
| 67 | +) -> Union[series.Series, bigframes.core.col.Expression]: |
69 | 68 | """Uses the matching key from keyset to decrypt ciphertext and verifies the integrity of the data using additional_data. Returns an error if decryption or verification fails.""" |
70 | | - return bigframes.bigquery._googlesql.apply_googlesql_scalar_op( |
| 69 | + return bigframes.core.googlesql.apply_googlesql_scalar_op( |
71 | 70 | _DECRYPT_BYTES_OP, |
72 | 71 | keyset, |
73 | 72 | ciphertext, |
74 | 73 | additional_data, |
75 | | - ) # type: ignore |
| 74 | + ) |
76 | 75 |
|
77 | 76 |
|
78 | 77 | def decrypt_string( |
79 | 78 | keyset: Union[ |
80 | | - T, |
| 79 | + series.Series, |
81 | 80 | bigframes.core.col.Expression, |
82 | 81 | Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], bytes, dict], |
83 | 82 | ], |
84 | 83 | ciphertext: Union[ |
85 | | - T, |
| 84 | + series.Series, |
86 | 85 | bigframes.core.col.Expression, |
87 | 86 | Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], bytes], |
88 | 87 | ], |
89 | 88 | additional_data: Union[ |
90 | | - T, |
| 89 | + series.Series, |
91 | 90 | bigframes.core.col.Expression, |
92 | 91 | Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], str], |
93 | 92 | ], |
94 | | -) -> T: |
| 93 | +) -> Union[series.Series, bigframes.core.col.Expression]: |
95 | 94 | """Like AEAD.DECRYPT_BYTES, but where additional_data is of type STRING.""" |
96 | | - return bigframes.bigquery._googlesql.apply_googlesql_scalar_op( |
| 95 | + return bigframes.core.googlesql.apply_googlesql_scalar_op( |
97 | 96 | _DECRYPT_STRING_OP, |
98 | 97 | keyset, |
99 | 98 | ciphertext, |
100 | 99 | additional_data, |
101 | | - ) # type: ignore |
| 100 | + ) |
102 | 101 |
|
103 | 102 |
|
104 | 103 | def encrypt( |
105 | 104 | keyset: Union[ |
106 | | - T, |
| 105 | + series.Series, |
107 | 106 | bigframes.core.col.Expression, |
108 | 107 | Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], bytes, dict], |
109 | 108 | ], |
110 | 109 | plaintext: Union[ |
111 | | - T, |
| 110 | + series.Series, |
112 | 111 | bigframes.core.col.Expression, |
113 | 112 | Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], bytes, str], |
114 | 113 | ], |
115 | 114 | additional_data: Union[ |
116 | | - T, |
| 115 | + series.Series, |
117 | 116 | bigframes.core.col.Expression, |
118 | 117 | Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], bytes, str], |
119 | 118 | ], |
120 | | -) -> T: |
| 119 | +) -> Union[series.Series, bigframes.core.col.Expression]: |
121 | 120 | """Encrypts plaintext using the primary cryptographic key in keyset. The algorithm of the primary key must be AEAD_AES_GCM_256. Binds the ciphertext to the context defined by additional_data. Returns NULL if any input is NULL.""" |
122 | | - return bigframes.bigquery._googlesql.apply_googlesql_scalar_op( |
| 121 | + return bigframes.core.googlesql.apply_googlesql_scalar_op( |
123 | 122 | _ENCRYPT_OP, |
124 | 123 | keyset, |
125 | 124 | plaintext, |
126 | 125 | additional_data, |
127 | | - ) # type: ignore |
| 126 | + ) |
0 commit comments