1
1
package io .scalajs .nodejs .crypto
2
2
3
3
import io .scalajs .nodejs .buffer .Buffer
4
- import io .scalajs .nodejs .stream .IDuplex
4
+ import io .scalajs .nodejs .stream .{ Transform , TransformOptions }
5
5
6
6
import scala .scalajs .js
7
7
@@ -16,7 +16,7 @@ import scala.scalajs.js
16
16
* are not to be created directly using the new keyword.
17
17
*/
18
18
@ js.native
19
- trait Cipher extends IDuplex {
19
+ sealed trait Cipher extends Transform {
20
20
21
21
/**
22
22
* Returns any remaining enciphered contents. If output_encoding parameter is one of 'binary', 'base64' or 'hex',
@@ -26,7 +26,7 @@ trait Cipher extends IDuplex {
26
26
* Attempts to call cipher.final() more than once will result in an error being thrown.
27
27
* @example cipher.final([output_encoding])
28
28
*/
29
- def `final` (output_encoding : String ): String = js.native
29
+ def `final` (outputEncoding : String ): String = js.native
30
30
31
31
/**
32
32
* Returns any remaining enciphered contents. If output_encoding parameter is one of 'binary', 'base64' or 'hex',
@@ -43,7 +43,7 @@ trait Cipher extends IDuplex {
43
43
* the value used for the additional authenticated data (AAD) input parameter.
44
44
* @example cipher.setAAD(buffer)
45
45
*/
46
- def setAAD (buffer : Buffer ): Unit = js.native
46
+ def setAAD (buffer : Buffer , options : SetAADOptions = js.native ): Cipher = js.native
47
47
48
48
/**
49
49
* When using an authenticated encryption mode (only GCM is currently supported), the cipher.getAuthTag() method
@@ -52,7 +52,7 @@ trait Cipher extends IDuplex {
52
52
* The cipher.getAuthTag() method should only be called after encryption has been completed using the cipher.final() method.
53
53
* @example cipher.getAuthTag()
54
54
*/
55
- def getAuthTag (): js. Any = js.native
55
+ def getAuthTag (): Buffer = js.native
56
56
57
57
/**
58
58
* When using block encryption algorithms, the Cipher class will automatically add padding to the input data to the
@@ -65,7 +65,7 @@ trait Cipher extends IDuplex {
65
65
* The cipher.setAutoPadding() method must be called before cipher.final().
66
66
* @example cipher.setAutoPadding(auto_padding=true)
67
67
*/
68
- def setAutoPadding (auto_padding : Boolean = js.native): Unit = js.native
68
+ def setAutoPadding (auto_padding : Boolean = js.native): Cipher = js.native
69
69
70
70
/**
71
71
* Updates the cipher with data. If the input_encoding argument is given, it's value must be one of 'utf8', 'ascii',
@@ -80,21 +80,13 @@ trait Cipher extends IDuplex {
80
80
* cipher.update() after cipher.final() will result in an error being thrown.
81
81
* @example cipher.update(data[, input_encoding][, output_encoding])
82
82
*/
83
- def update (data : String , input_encoding : String , output_encoding : String = js.native): String = js.native
84
-
85
- /**
86
- * Updates the cipher with data. If the input_encoding argument is given, it's value must be one of 'utf8', 'ascii',
87
- * or 'binary' and the data argument is a string using the specified encoding. If the input_encoding argument is not
88
- * given, data must be a Buffer. If data is a Buffer then input_encoding is ignored.
89
- *
90
- * The output_encoding specifies the output format of the enciphered data, and can be 'binary', 'base64' or 'hex'.
91
- * If the output_encoding is specified, a string using the specified encoding is returned. If no output_encoding is
92
- * provided, a Buffer is returned.
93
- *
94
- * The cipher.update() method can be called multiple times with new data until cipher.final() is called. Calling
95
- * cipher.update() after cipher.final() will result in an error being thrown.
96
- * @example cipher.update(data[, input_encoding][, output_encoding])
97
- */
98
- def update (data : Buffer ): Buffer = js.native
83
+ def update (data : String , inputEncoding : String , outputEncoding : String ): String = js.native
84
+ def update (data : String , inputEncoding : String ): Buffer = js.native
85
+ def update (data : BufferLike ): Buffer = js.native
99
86
100
87
}
88
+
89
+ class SetAADOptions (override val transform : js.UndefOr [js.Function ] = js.undefined,
90
+ override val flush : js.UndefOr [js.Function ] = js.undefined,
91
+ val plaintextLength : js.UndefOr [Int ] = js.undefined)
92
+ extends TransformOptions (transform, flush) {}
0 commit comments