-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14d7c30
commit 55c1df5
Showing
6 changed files
with
16 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,13 @@ | ||
// Copyright 2024 LiveKit, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
/* | ||
import 'dart:async'; | ||
import 'dart:js_util' as jsutil; | ||
import 'dart:js_interop'; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:js/js.dart'; | ||
import 'package:web/web.dart' as web; | ||
@JS('Promise') | ||
class Promise<T> { | ||
external factory Promise._(); | ||
} | ||
@JS('Algorithm') | ||
class Algorithm { | ||
external String get name; | ||
} | ||
@JS('crypto.subtle.encrypt') | ||
external Promise<ByteBuffer> encrypt( | ||
dynamic algorithm, | ||
web.CryptoKey key, | ||
ByteBuffer data, | ||
); | ||
@JS('crypto.subtle.decrypt') | ||
external Promise<ByteBuffer> decrypt( | ||
dynamic algorithm, | ||
web.CryptoKey key, | ||
ByteBuffer data, | ||
); | ||
@JS() | ||
@anonymous | ||
class AesGcmParams { | ||
external factory AesGcmParams({ | ||
required String name, | ||
required ByteBuffer iv, | ||
ByteBuffer? additionalData, | ||
int tagLength = 128, | ||
}); | ||
} | ||
ByteBuffer jsArrayBufferFrom(List<int> data) { | ||
JSArrayBuffer jsArrayBufferFrom(ByteData data) { | ||
// Avoid copying if possible | ||
if (data is Uint8List && | ||
data.offsetInBytes == 0 && | ||
data.lengthInBytes == data.buffer.lengthInBytes) { | ||
return data.buffer; | ||
return data.buffer.toJS; | ||
} | ||
// Copy | ||
return Uint8List.fromList(data).buffer; | ||
} | ||
@JS('crypto.subtle.importKey') | ||
external Promise<web.CryptoKey> importKey( | ||
String format, | ||
ByteBuffer keyData, | ||
dynamic algorithm, | ||
bool extractable, | ||
List<String> keyUsages, | ||
); | ||
@JS('crypto.subtle.exportKey') | ||
external Promise<ByteBuffer> exportKey( | ||
String format, | ||
web.CryptoKey key, | ||
); | ||
@JS('crypto.subtle.deriveKey') | ||
external Promise<web.CryptoKey> deriveKey( | ||
dynamic algorithm, | ||
web.CryptoKey baseKey, | ||
dynamic derivedKeyAlgorithm, | ||
bool extractable, | ||
List<String> keyUsages); | ||
@JS('crypto.subtle.deriveBits') | ||
external Promise<ByteBuffer> deriveBits( | ||
dynamic algorithm, | ||
web.CryptoKey baseKey, | ||
int length, | ||
); | ||
Future<web.CryptoKey> impportKeyFromRawData(List<int> secretKeyData, | ||
{required String webCryptoAlgorithm, | ||
required List<String> keyUsages}) async { | ||
return jsutil.promiseToFuture<web.CryptoKey>(importKey( | ||
'raw', | ||
jsArrayBufferFrom(secretKeyData), | ||
jsutil.jsify({'name': webCryptoAlgorithm}), | ||
false, | ||
keyUsages, | ||
)); | ||
return Uint8List.fromList(Uint8List.sublistView(data)).buffer.toJS; | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters