11package io .scalajs .nodejs .crypto
22
33import io .scalajs .nodejs .buffer .Buffer
4- import io .scalajs .nodejs .stream .IDuplex
4+ import io .scalajs .nodejs .stream .{ Transform , TransformOptions }
55
66import scala .scalajs .js
77
@@ -16,7 +16,7 @@ import scala.scalajs.js
1616 * are not to be created directly using the new keyword.
1717 */
1818@ js.native
19- trait Cipher extends IDuplex {
19+ sealed trait Cipher extends Transform {
2020
2121 /**
2222 * Returns any remaining enciphered contents. If output_encoding parameter is one of 'binary', 'base64' or 'hex',
@@ -26,7 +26,7 @@ trait Cipher extends IDuplex {
2626 * Attempts to call cipher.final() more than once will result in an error being thrown.
2727 * @example cipher.final([output_encoding])
2828 */
29- def `final` (output_encoding : String ): String = js.native
29+ def `final` (outputEncoding : String ): String = js.native
3030
3131 /**
3232 * Returns any remaining enciphered contents. If output_encoding parameter is one of 'binary', 'base64' or 'hex',
@@ -43,7 +43,7 @@ trait Cipher extends IDuplex {
4343 * the value used for the additional authenticated data (AAD) input parameter.
4444 * @example cipher.setAAD(buffer)
4545 */
46- def setAAD (buffer : Buffer ): Unit = js.native
46+ def setAAD (buffer : Buffer , options : SetAADOptions = js.native ): Cipher = js.native
4747
4848 /**
4949 * When using an authenticated encryption mode (only GCM is currently supported), the cipher.getAuthTag() method
@@ -52,7 +52,7 @@ trait Cipher extends IDuplex {
5252 * The cipher.getAuthTag() method should only be called after encryption has been completed using the cipher.final() method.
5353 * @example cipher.getAuthTag()
5454 */
55- def getAuthTag (): js. Any = js.native
55+ def getAuthTag (): Buffer = js.native
5656
5757 /**
5858 * 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 {
6565 * The cipher.setAutoPadding() method must be called before cipher.final().
6666 * @example cipher.setAutoPadding(auto_padding=true)
6767 */
68- def setAutoPadding (auto_padding : Boolean = js.native): Unit = js.native
68+ def setAutoPadding (auto_padding : Boolean = js.native): Cipher = js.native
6969
7070 /**
7171 * 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 {
8080 * cipher.update() after cipher.final() will result in an error being thrown.
8181 * @example cipher.update(data[, input_encoding][, output_encoding])
8282 */
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
9986
10087}
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