Skip to content

Commit

Permalink
Optimizing Decodes and null parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Nov 24, 2020
1 parent f9f3115 commit 1a63652
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
9 changes: 8 additions & 1 deletion app/components/VaccineCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import Moment from 'moment';

export default class VaccineCard extends Component {

format = (list) => {
const noUndefinedList = list.filter(item => item);
return noUndefinedList.join(', ');
}

render() {
return (
<Card containerStyle={styles.card}>
Expand All @@ -25,7 +30,9 @@ export default class VaccineCard extends Component {
</View>

<View style={{flexDirection:'row', justifyContent:'space-between'}}>
<Text style={styles.notes}>{this.props.detail.site}, {this.props.detail.route}, {this.props.detail.dose}ml</Text>
<Text style={styles.notes}>
{this.format([this.props.detail.site, this.props.detail.route, this.props.detail.dose])}
</Text>
</View>

<Divider style={{ backgroundColor: '#dfe6e9', marginVertical:15}} />
Expand Down
31 changes: 18 additions & 13 deletions app/screens/QRReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const screenHeight = Math.round(Dimensions.get('window').height);
function QRReader({ navigation }) {
const {colors, isDark} = useTheme();

const myDecode = (uriComponent) => {
return uriComponent ? decodeURIComponent(uriComponent).replace(/\+/g, ' ') : undefined;
}

const onVaccineRead = async (e) => {
const msg = e.data.split("?");
const what = msg[0].split(":");
Expand All @@ -33,34 +37,35 @@ function QRReader({ navigation }) {
match;
while (match = regex.exec(e.data)) {
params[match[1]] = match[2];
console.log(match[1], params[match[1]]);
}

try {
let pub_key_response = await fetch(params.vaccinator_pub_key);
let pub_key = await pub_key_response.text();

console.log(params.signature);

const message = e.data.replace("&signature="+params.signature, "");
const message = e.data.replace("&signature="+params.signature, "");

console.log(message);
console.log(decodeURIComponent(params.signature).replace(/\n/g, ''));

const signedCert = base64.decode(decodeURIComponent(params.signature).replace(/\n/g, ''));
const validSignature2 = await RNSimpleCrypto.RSA.verify(
signedCert,
message,
pub_key,
"SHA256"
);

const vaccine = { type: what[1],
date: params.date,
name: decodeURIComponent(params.name).replace(/\+/g, ' '),
manufacturer: decodeURIComponent(params.manuf).replace(/\+/g, ' '),
lot: decodeURIComponent(params.lot).replace(/\+/g, ' '),
route: decodeURIComponent(params.route).replace(/\+/g, ' '),
site: decodeURIComponent(params.site).replace(/\+/g, ' '),
dose: decodeURIComponent(params.dose).replace(/\+/g, ' '),
vaccinee: decodeURIComponent(params.vaccinee).replace(/\+/g, ' '),
vaccinator: decodeURIComponent(params.vaccinator).replace(/\+/g, ' '),
name: myDecode(params.name),
manufacturer: myDecode(params.manuf),
lot: myDecode(params.lot),
route: myDecode(params.route),
site: myDecode(params.site),
dose: myDecode(params.dose),
vaccinee: myDecode(params.vaccinee),
vaccinator: myDecode(params.vaccinator),
vaccinator_pub_key: params.vaccinator_pub_key,
signature: signedCert,
scanDate: new Date().toJSON(),
Expand Down

0 comments on commit 1a63652

Please sign in to comment.