Skip to content

Commit

Permalink
Merge pull request #60 from cryptoeng/enter-data-helper-fixes
Browse files Browse the repository at this point in the history
Fixes some issues with enter-data-helper
  • Loading branch information
taudor committed Apr 17, 2020
2 parents 94198c0 + 150a29a commit 3c892be
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 50 deletions.
3 changes: 2 additions & 1 deletion schema/flavor.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "object",
"properties": {
"name": {
"type": "string"
"type": "string",
"$comment": "Human readable name (full, including the scheme name)"
},
"comment": {
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion schema/implementation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "object",
"properties": {
"name": {
"type": "string"
"type": "string",
"$comment": "Human readable name (don't include scheme/flavor name, but do include the parameter set if the implementation is specific to it)"
},
"comment": {
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion schema/paramset.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "object",
"properties": {
"name": {
"type": "string"
"type": "string",
"$comment": "Human readable name (full, including scheme and flavor name)"
},
"comment": {
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion schema/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"$comment": "`enc` stands for all types of key exchange (KEMs etc)"
},
"name": {
"type": "string"
"type": "string",
"$comment": "Human readable name"
},
"comment": {
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion tools/enter-data-helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"electron": "concurrently \"BROWSER=none HOST=localhost yarn start\" \"wait-on http://localhost:3000 && electron . ../..\"",
"electron": "concurrently --kill-others \"BROWSER=none HOST=localhost yarn start\" \"wait-on http://localhost:3000 && electron . ../..\"",
"package-linux": "electron-builder -l",
"package-mac": "electron-builder -m && tar -czf dist/enter-data-helper-mac.tar.gz -C dist/mac enter-data-helper.app"
},
Expand Down
6 changes: 3 additions & 3 deletions tools/enter-data-helper/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class App extends React.Component {
<NavBarRouter setTheme={this.setTheme.bind(this)} theme={this.state.themeId} />
<Container>
<Switch>
<Route path='/:type/:schemeName/:name/:subType/:subName' component={SubtypeOverview} />
<Route path='/:type/:schemeName/:name/' component={FlavorOverview} />
<Route path='/:type/:name/' component={SchemeOverview} />
<Route path='/:type/:schemeIdentifier/:flavorIdentifier/:subType/:subIdentifier' component={SubtypeOverview} />
<Route path='/:type/:schemeIdentifier/:flavorIdentifier/' component={FlavorOverview} />
<Route path='/:type/:schemeIdentifier/' component={SchemeOverview} />
<Route exact path='/' component={SelectScheme} />
</Switch>
<Snackbar key={this.state.alertMsg} autoHideDuration={6000}
Expand Down
11 changes: 9 additions & 2 deletions tools/enter-data-helper/src/components/BaseComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,21 @@ class JsonFormsContainer extends React.Component {
class SelectList extends React.Component {
constructor(props) {
super(props);
this.entries = props.entries;
this.state = {entries: props.entries};
}

componentDidUpdate(prevProps, prevState) {
if (prevProps.entries !== this.props.entries) {
this.setState({ entries: this.props.entries });
}
}

render() {
return (
<Paper>
<List component="ul">
{
this.entries.map(entry => (
this.state.entries.map(entry => (
<ListItem button key={"item-" + entry} onClick={() => this.props.action(entry)}>
<ListItemText primary={entry} />
<ListItemIcon>
Expand Down Expand Up @@ -201,6 +207,7 @@ class SelectOrCreate extends JsonFormsContainer {
type: "object", properties: {
identifier: {
type: "string",
title: "Identifier (short name used as file name)",
pattern: this.regex
}
}, required: ["identifier"]
Expand Down
38 changes: 19 additions & 19 deletions tools/enter-data-helper/src/components/FlavorOverview.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class EditFlavor extends JsonFormsContainer {
constructor(props) {
super(props)
this.type = props.type;
this.schemeName = props.schemeName;
this.name = props.name;
this.flavorFile = path.join(typeDirs[this.type], this.schemeName, this.name, this.name + '.yaml');
this.schemeIdentifier = props.schemeIdentifier;
this.flavorIdentifier = props.flavorIdentifier;
this.flavorFile = path.join(typeDirs[this.type], this.schemeIdentifier, this.flavorIdentifier, this.flavorIdentifier + '.yaml');
this.dataStore = yaml.load(fs.readFileSync(this.flavorFile, 'utf-8'));
this.state.schema = JSON.parse(fs.readFileSync(path.join(ROOT_DIR, 'schema', 'flavor.json'), 'utf-8'));
this.state.uiSchema = Generate.uiSchema(this.state.schema);
Expand Down Expand Up @@ -52,18 +52,18 @@ class SubtypeOverview extends JsonFormsContainer {
constructor(props) {
super(props)
this.type = props.match.params.type;
this.schemeName = props.match.params.schemeName;
this.name = props.match.params.name;
this.schemeIdentifier = props.match.params.schemeIdentifier;
this.flavorIdentifier = props.match.params.flavorIdentifier;
this.subType = props.match.params.subType;
this.subName = props.match.params.subName;
this.subIdentifier = props.match.params.subIdentifier;

this.targetFile = path.join(typeDirs[this.type], this.schemeName, this.name, this.subType, this.subName + '.yaml');
this.targetFile = path.join(typeDirs[this.type], this.schemeIdentifier, this.flavorIdentifier, this.subType, this.subIdentifier + '.yaml');
this.dataStore = yaml.load(fs.readFileSync(this.targetFile, 'utf-8'));
this.state.schema = JSON.parse(fs.readFileSync(path.join(ROOT_DIR, 'schema',
{ 'bench': 'benchmark', 'param': 'paramset', 'impl': 'implementation' }[this.subType] + '.json')));
this.state.uiSchema = Generate.uiSchema(this.state.schema);
if (this.subType === 'bench') {
var parts = this.subName.split('_');
var parts = this.subIdentifier.split('_');
this.dataStore.impl = parts[0];
this.dataStore.param = parts[1];
disableUIElements(this.state.uiSchema, ['#/properties/impl', '#/properties/param']);
Expand Down Expand Up @@ -105,10 +105,10 @@ class SubtypeOverview extends JsonFormsContainer {
class FlavorOverview extends React.Component {
constructor(props) {
super(props)
this.schemeName = props.match.params.schemeName;
this.name = props.match.params.name;
this.schemeIdentifier = props.match.params.schemeIdentifier;
this.identifier = props.match.params.flavorIdentifier;
this.type = props.match.params.type;
this.baseDir = path.join(typeDirs[this.type], this.schemeName, this.name);
this.baseDir = path.join(typeDirs[this.type], this.schemeIdentifier, this.identifier);
this.state = {
param: this.generateChoices('param'),
impl: this.generateChoices('impl'),
Expand All @@ -124,8 +124,8 @@ class FlavorOverview extends React.Component {
.filter(x => x.endsWith('.yaml')).map(x => x.substring(0, x.length - 5));
}

submitForm(name, type, create) {
if (create === fs.existsSync(path.join(this.baseDir, type, name + ".yaml"))) {
submitForm(identifier, type, create) {
if (create === fs.existsSync(path.join(this.baseDir, type, identifier + ".yaml"))) {
showAlert('Error. Unexpected existance or non-existance of flavor file.', 'error');
return;
}
Expand All @@ -134,11 +134,11 @@ class FlavorOverview extends React.Component {
try {
var dir = path.join(this.baseDir, type);
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
var data = (type === 'bench') ? { platform: name.split('_')[2] } : { name: name };
fs.writeFileSync(path.join(dir, name + ".yaml"), yaml.dump(data));
showAlert('"' + name + '" was successfully created.', 'success');
var data = {};
fs.writeFileSync(path.join(dir, identifier + ".yaml"), yaml.dump(data));
showAlert('"' + identifier + '" was successfully created.', 'success');
} catch {
showAlert('"' + name + '" could not be created.', 'error');
showAlert('"' + identifier + '" could not be created.', 'error');
}

var newState = {};
Expand All @@ -148,7 +148,7 @@ class FlavorOverview extends React.Component {
return;
}

this.history.push(this.history.location.pathname + type + '/' + name + '/');
this.history.push(this.history.location.pathname + type + '/' + identifier + '/');
window.scrollTo(0, 0);
}

Expand All @@ -159,7 +159,7 @@ class FlavorOverview extends React.Component {
<Paper>
<Box px={2} pt={1} pb={2}>
<h2>Flavor Properties</h2>
<EditFlavor type={this.type} schemeName={this.schemeName} name={this.name} />
<EditFlavor type={this.type} schemeIdentifier={this.schemeIdentifier} flavorIdentifier={this.identifier} />
</Box>
</Paper>
</Grid>
Expand Down
26 changes: 13 additions & 13 deletions tools/enter-data-helper/src/components/SchemeOverview.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class EditScheme extends JsonFormsContainer {
constructor(props) {
super(props)
this.type = props.type;
this.name = props.name;
this.schemeFile = path.join(typeDirs[this.type], this.name, this.name + '.yaml');
this.identifier = props.identifier;
this.schemeFile = path.join(typeDirs[this.type], this.identifier, this.identifier + '.yaml');
this.dataStore = yaml.load(fs.readFileSync(this.schemeFile, 'utf-8'));
this.dataStore.type = this.type;
if (!('stateful' in this.dataStore))
Expand Down Expand Up @@ -56,36 +56,36 @@ class EditScheme extends JsonFormsContainer {
class SchemeOverview extends React.Component {
constructor(props) {
super(props)
this.name = props.match.params.name;
this.identifier = props.match.params.schemeIdentifier;
this.type = props.match.params.type;
this.baseDir = path.join(typeDirs[this.type], this.name);
this.baseDir = path.join(typeDirs[this.type], this.identifier);
this.state = { flavors: listDirs(this.baseDir) };
this.history = props.history;
}

submitForm(name, create) {
if (create === fs.existsSync(path.join(this.baseDir, name, name + ".yaml"))) {
submitForm(identifier, create) {
if (create === fs.existsSync(path.join(this.baseDir, identifier, identifier + ".yaml"))) {
showAlert("Error. Unexpected existance or non-existance of flavor file.", "error");
return;
}

if (create) {
try {
var dir = path.join(this.baseDir, name);
var dir = path.join(this.baseDir, identifier);
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
['', 'bench', 'impl', 'param'].map(x => path.join(dir, x))
.filter(x => !fs.existsSync(x)).forEach(x => fs.mkdirSync(x));
var data = { name: name };
fs.writeFileSync(path.join(dir, name + ".yaml"), yaml.dump(data));
showAlert('Flavor "' + name + '" was successfully created.', 'success');
var data = {};
fs.writeFileSync(path.join(dir, identifier + ".yaml"), yaml.dump(data));
showAlert('Flavor "' + identifier + '" was successfully created.', 'success');
} catch {
showAlert('Flavor "' + name + '" could not be created.', 'error');
showAlert('Flavor "' + identifier + '" could not be created.', 'error');
}

this.setState({ flavors: listDirs(this.baseDir) });
return;
}
var link = this.history.location.pathname + name + "/";
var link = this.history.location.pathname + identifier + "/";
this.history.push(link);
window.scrollTo(0, 0);
}
Expand All @@ -97,7 +97,7 @@ class SchemeOverview extends React.Component {
<Paper >
<Box px={2} pt={1} pb={2}>
<h2>Scheme Properties</h2>
<EditScheme type={this.type} name={this.name} />
<EditScheme type={this.type} identifier={this.identifier} />
</Box>
</Paper>
</Grid>
Expand Down
16 changes: 8 additions & 8 deletions tools/enter-data-helper/src/components/SelectScheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ class SelectScheme extends React.Component {
};
}

submitForm(type, name, create) {
if (create === fs.existsSync(path.join(this.typeDirs[type], name, name + ".yaml"))) {
submitForm(type, identifier, create) {
if (create === fs.existsSync(path.join(this.typeDirs[type], identifier, identifier + ".yaml"))) {
showAlert("Error. Unexpected existance or non-existance of scheme file.", "error");
return;
}

if (create) {
try {
var dir = path.join(this.typeDirs[type], name);
var dir = path.join(this.typeDirs[type], identifier);
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
var data = { name: name };
fs.writeFileSync(path.join(dir, name + ".yaml"), yaml.dump(data));
showAlert('Scheme "' + name + '" was successfully created.', 'success');
var data = {};
fs.writeFileSync(path.join(dir, identifier + ".yaml"), yaml.dump(data));
showAlert('Scheme "' + identifier + '" was successfully created.', 'success');
} catch {
showAlert('Scheme "' + name + '" could not be created.', 'error');
showAlert('Scheme "' + identifier + '" could not be created.', 'error');
}

var newState = {};
Expand All @@ -42,7 +42,7 @@ class SelectScheme extends React.Component {
return;
}

this.history.push('/' + type + '/' + name + '/');
this.history.push('/' + type + '/' + identifier + '/');
window.scrollTo(0, 0);
}

Expand Down

0 comments on commit 3c892be

Please sign in to comment.