Skip to content

Commit 70a9650

Browse files
authored
fix: accept any OpenSSL curve name in EC generateKeyPair, add ECDSA stress tests (#930)
1 parent e4b63a7 commit 70a9650

17 files changed

Lines changed: 469 additions & 170 deletions

File tree

example/src/components/TestItem.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type TestItemProps = {
1515
isFooter?: boolean;
1616
passCount?: number;
1717
failCount?: number;
18+
detailsScreen?: string;
1819
};
1920

2021
export const TestItem: React.FC<TestItemProps> = ({
@@ -27,6 +28,7 @@ export const TestItem: React.FC<TestItemProps> = ({
2728
isFooter = false,
2829
passCount,
2930
failCount,
31+
detailsScreen = 'TestDetailsScreen',
3032
}: TestItemProps) => {
3133
const navigation = useNavigation();
3234

@@ -65,7 +67,7 @@ export const TestItem: React.FC<TestItemProps> = ({
6567
onPress={() => {
6668
if (!isFooter) {
6769
// @ts-expect-error - not dealing with navigation types rn
68-
navigation.navigate('TestDetailsScreen', {
70+
navigation.navigate(detailsScreen, {
6971
results,
7072
suiteName: description,
7173
});

example/src/hooks/useStressList.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { TestSuites } from '../types/tests';
2+
import { StressContext } from '../stress/util';
3+
import { useSuiteList } from './useSuiteList';
4+
5+
import '../stress/ecdsa_sign_verify';
6+
7+
export const useStressList = (): [
8+
TestSuites,
9+
(description: string) => void,
10+
() => void,
11+
() => void,
12+
] => useSuiteList(StressContext);

example/src/hooks/useSuiteList.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { useState, useCallback } from 'react';
2+
import type { TestSuites } from '../types/tests';
3+
4+
export const useSuiteList = (
5+
initialContext: TestSuites,
6+
): [TestSuites, (description: string) => void, () => void, () => void] => {
7+
const [suites, setSuites] = useState<TestSuites>(initialContext);
8+
9+
const toggle = useCallback((description: string) => {
10+
setSuites(prevSuites => {
11+
const newSuites = { ...prevSuites };
12+
if (newSuites[description]) {
13+
newSuites[description] = {
14+
...newSuites[description],
15+
value: !newSuites[description].value,
16+
};
17+
}
18+
return newSuites;
19+
});
20+
}, []);
21+
22+
const clearAll = useCallback(() => {
23+
setSuites(
24+
prevSuites =>
25+
Object.fromEntries(
26+
Object.entries(prevSuites).map(([key, suite]) => [
27+
key,
28+
{ ...suite, value: false },
29+
]),
30+
) as TestSuites,
31+
);
32+
}, []);
33+
34+
const checkAll = useCallback(() => {
35+
setSuites(
36+
prevSuites =>
37+
Object.fromEntries(
38+
Object.entries(prevSuites).map(([key, suite]) => [
39+
key,
40+
{ ...suite, value: true },
41+
]),
42+
) as TestSuites,
43+
);
44+
}, []);
45+
46+
return [suites, toggle, clearAll, checkAll];
47+
};

example/src/hooks/useTestsList.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useState, useCallback } from 'react';
21
import type { TestSuites } from '../types/tests';
32
import { TestsContext } from '../tests/util';
3+
import { useSuiteList } from './useSuiteList';
44

55
import '../tests/argon2/argon2_tests';
66
import '../tests/blake3/blake3_tests';
@@ -49,42 +49,4 @@ export const useTestsList = (): [
4949
(description: string) => void,
5050
() => void,
5151
() => void,
52-
] => {
53-
const [suites, setSuites] = useState<TestSuites>(TestsContext);
54-
55-
const toggle = useCallback(
56-
(description: string) => {
57-
setSuites(prevSuites => {
58-
const newSuites = { ...prevSuites };
59-
if (newSuites[description]) {
60-
newSuites[description] = {
61-
...newSuites[description],
62-
value: !newSuites[description].value,
63-
};
64-
}
65-
return newSuites;
66-
});
67-
},
68-
[setSuites],
69-
);
70-
71-
const clearAll = useCallback(() => {
72-
setSuites(suites => {
73-
Object.values(suites).forEach(suite => {
74-
suite.value = false;
75-
});
76-
return { ...suites };
77-
});
78-
}, [setSuites]);
79-
80-
const checkAll = useCallback(() => {
81-
setSuites(suites => {
82-
Object.values(suites).forEach(suite => {
83-
suite.value = true;
84-
});
85-
return { ...suites };
86-
});
87-
}, [setSuites]);
88-
89-
return [suites, toggle, clearAll, checkAll];
90-
};
52+
] => useSuiteList(TestsContext);

example/src/navigators/Root.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NavigationContainer } from '@react-navigation/native';
33
import { enableFreeze } from 'react-native-screens';
44
import { TestStack } from './children/TestStack';
55
import { BenchmarkStack } from './children/BenchmarkStack';
6+
import { StressStack } from './children/StressStack';
67
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
78
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
89

@@ -33,6 +34,16 @@ export const Root: React.FC = () => {
3334
),
3435
}}
3536
/>
37+
<Tab.Screen
38+
name="Stress"
39+
component={StressStack}
40+
options={{
41+
headerShown: false,
42+
tabBarIcon: ({ color }) => (
43+
<Icon name="repeat" size={24} color={color} />
44+
),
45+
}}
46+
/>
3647
</Tab.Navigator>
3748
</NavigationContainer>
3849
);
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import React, { useState } from 'react';
2+
import { ScrollView, StyleSheet, Text, View } from 'react-native';
3+
import { SafeAreaView } from 'react-native-safe-area-context';
4+
import BouncyCheckbox from 'react-native-bouncy-checkbox';
5+
import { CorrectResultItem } from '../../components/CorrectResultItem';
6+
import { IncorrectResultItem } from '../../components/IncorrectResultItem';
7+
import { Suite } from '../../components/Suite';
8+
import type { RouteParams } from '../../types/Results';
9+
import { colors } from '../../styles/colors';
10+
11+
interface DetailsScreenProps {
12+
titlePrefix: string;
13+
route: { params: RouteParams };
14+
}
15+
16+
export const DetailsScreen: React.FC<DetailsScreenProps> = ({
17+
titlePrefix,
18+
route,
19+
}) => {
20+
const { results, suiteName }: RouteParams = route.params;
21+
const [showFailed, setShowFailed] = useState<boolean>(true);
22+
const [showPassed, setShowPassed] = useState<boolean>(true);
23+
24+
return (
25+
<SafeAreaView style={styles.container} edges={['left', 'right']}>
26+
<View>
27+
<Text style={styles.title}>
28+
{titlePrefix} Results for '{suiteName}' Suite
29+
</Text>
30+
</View>
31+
<View style={styles.showMenu}>
32+
<View style={styles.showMenuItem}>
33+
<BouncyCheckbox
34+
isChecked={showFailed}
35+
onPress={() => setShowFailed(!showFailed)}
36+
fillColor="red"
37+
style={styles.checkbox}
38+
testID="show-failed-checkbox"
39+
disableBuiltInState={true}
40+
/>
41+
<Text style={styles.showMenuLabel}>Show Failed</Text>
42+
</View>
43+
<View style={styles.showMenuItem}>
44+
<BouncyCheckbox
45+
isChecked={showPassed}
46+
onPress={() => setShowPassed(!showPassed)}
47+
fillColor={colors.green}
48+
style={styles.checkbox}
49+
testID="show-passed-checkbox"
50+
disableBuiltInState={true}
51+
/>
52+
<Text style={styles.showMenuLabel}>Show Passed</Text>
53+
</View>
54+
</View>
55+
<ScrollView
56+
style={styles.scroll}
57+
contentContainerStyle={styles.scrollContent}
58+
>
59+
{results.map((it, index: number) => {
60+
let InnerElement = <View key={index} />;
61+
if (showPassed && it.type === 'correct') {
62+
InnerElement = (
63+
<CorrectResultItem key={index} description={it.description} />
64+
);
65+
}
66+
if (showFailed && it.type === 'incorrect') {
67+
const errorMsg = it.errorMsg || '';
68+
InnerElement = (
69+
<IncorrectResultItem
70+
key={index}
71+
description={it.description}
72+
errorMsg={errorMsg}
73+
/>
74+
);
75+
}
76+
if (it.type === 'grouping') {
77+
InnerElement = <Suite key={index} description={it.description} />;
78+
}
79+
return InnerElement;
80+
})}
81+
</ScrollView>
82+
</SafeAreaView>
83+
);
84+
};
85+
86+
const styles = StyleSheet.create({
87+
container: {
88+
flex: 1,
89+
paddingBottom: 30,
90+
},
91+
title: {
92+
textAlign: 'center',
93+
paddingVertical: 5,
94+
},
95+
showMenu: {
96+
flexDirection: 'row',
97+
width: '100%',
98+
justifyContent: 'space-evenly',
99+
paddingBottom: 5,
100+
},
101+
showMenuItem: {
102+
flexDirection: 'row',
103+
alignItems: 'center',
104+
},
105+
showMenuLabel: {
106+
paddingLeft: 5,
107+
},
108+
scroll: {
109+
width: '100%',
110+
},
111+
scrollContent: {
112+
paddingHorizontal: 5,
113+
},
114+
checkbox: {
115+
transform: [{ scaleX: 0.8 }, { scaleY: 0.8 }],
116+
},
117+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
import { DetailsScreen } from './DetailsScreen';
3+
4+
// @ts-expect-error - not dealing with navigation types rn
5+
export const StressDetailsScreen = ({ route }) => (
6+
<DetailsScreen titlePrefix="Stress" route={route} />
7+
);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
3+
import { StressSuitesScreen } from './StressSuitesScreen';
4+
import { StressDetailsScreen } from './StressDetailsScreen';
5+
6+
const Stack = createNativeStackNavigator();
7+
8+
export const StressStack = () => {
9+
return (
10+
<Stack.Navigator>
11+
<Stack.Screen
12+
name="StressSuites"
13+
component={StressSuitesScreen}
14+
options={{ title: 'Stress Suites' }}
15+
/>
16+
<Stack.Screen
17+
name="StressDetailsScreen"
18+
component={StressDetailsScreen}
19+
options={{ title: 'Stress Details' }}
20+
/>
21+
</Stack.Navigator>
22+
);
23+
};

0 commit comments

Comments
 (0)