|
13 | 13 | * SPDX-License-Identifier: EPL-2.0 OR W3C-20150513 |
14 | 14 | ********************************************************************************/ |
15 | 15 |
|
16 | | -import { coerceSecurityPolicy, MessageSecurityMode, OPCUAClient, s, SecurityPolicy } from "node-opcua-client"; |
| 16 | +import { MessageSecurityMode, OPCUAClient, SecurityPolicy } from "node-opcua-client"; |
17 | 17 |
|
18 | 18 | function getPriority(securityPolicy: string | null, securityMode: MessageSecurityMode): number { |
19 | 19 | const encryptWeight = securityMode === MessageSecurityMode.SignAndEncrypt ? 100 : 0; |
@@ -77,26 +77,22 @@ interface EndpointDescriptionMini { |
77 | 77 | securityPolicyUri: string | null; |
78 | 78 | } |
79 | 79 |
|
| 80 | +const defaultEndpoint: EndpointDescriptionMini = { |
| 81 | + endpointUrl: null, |
| 82 | + securityMode: MessageSecurityMode.None, |
| 83 | + securityPolicyUri: SecurityPolicy.None, |
| 84 | +}; |
| 85 | + |
80 | 86 | async function findMostSecureChannelInternal(client: OPCUAClient): Promise<EndpointDescriptionMini> { |
81 | 87 | let endpoints = await client.getEndpoints(); |
82 | 88 |
|
83 | 89 | // sort in descending order of security level |
84 | 90 | endpoints = endpoints.sort((a, b) => { |
85 | 91 | const securityLevelA = getPriority(a.securityPolicyUri, a.securityMode); |
86 | 92 | const securityLevelB = getPriority(b.securityPolicyUri, b.securityMode); |
87 | | - if (securityLevelA !== securityLevelB) { |
88 | | - return securityLevelB - securityLevelA; |
89 | | - } |
90 | | - // keep original order |
91 | | - return 0; |
| 93 | + return securityLevelB - securityLevelA; |
92 | 94 | }); |
93 | | - return ( |
94 | | - endpoints[0]! || { |
95 | | - endpointUrl: null, |
96 | | - securityMode: MessageSecurityMode.None, |
97 | | - securityPolicyUri: SecurityPolicy.None, |
98 | | - } |
99 | | - ); |
| 95 | + return endpoints.length > 0 ? endpoints[0] : defaultEndpoint; |
100 | 96 | } |
101 | 97 |
|
102 | 98 | export async function findMostSecureChannel( |
|
0 commit comments