| // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| // |
| // Confirm error message when private key value is missing. |
| |
| import 'dart:io'; |
| import 'dart:typed_data'; |
| |
| import "package:expect/expect.dart"; |
| |
| void main() { |
| // Handcrafted private key with actual value missing(dartbug.com/54719) |
| Uint8List privateKeyBytes = Uint8List.fromList(<int>[ |
| 0x30, 0x53, 0x02, 0x01, 0x03, 0x30, 0x0b, 0x06, 0x09, 0x2a, 0x86, 0x48, |
| 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0x30, 0x41, 0x30, 0x31, 0x30, 0x0d, |
| 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, |
| 0x00, 0x04, 0x20, 0xfc, 0x85, 0xd5, 0xb6, 0xc7, 0x78, 0x80, 0x96, 0x74, |
| 0x5b, 0x13, 0xe4, 0x14, 0x79, 0x56, 0x39, 0xd1, 0xa3, 0x1b, 0x0e, 0xf9, |
| 0x21, 0x22, 0x9a, 0xe8, 0x03, 0x91, 0x98, 0xf4, 0xb6, 0x3d, 0x3f, 0x04, |
| 0x08, 0x91, 0xc1, 0x65, 0x4e, 0xe5, 0x58, 0x43, 0xf0, 0x02, 0x02, 0x08, |
| 0x00]); |
| |
| SecurityContext securityContext = SecurityContext(); |
| Expect.throws( |
| () => securityContext.usePrivateKeyBytes(privateKeyBytes), |
| (e) => |
| e is ArgumentError && e.toString().contains("Expected private key")); |
| } |