Skip to content

Commit

Permalink
Rename the QrCodeData methods so they use camel case
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed Jun 14, 2024
1 parent 2c9bd6f commit 0d58c68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/qr_login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl QrCodeData {
/// Attempt to decode a slice of bytes into a {@link QrCodeData} object.
///
/// The slice of bytes would generally be returned by a QR code decoder.
#[wasm_bindgen(js_name = "fromBytes")]
pub fn from_bytes(bytes: &[u8]) -> Result<QrCodeData, JsError> {
Ok(Self { inner: qr_login::QrCodeData::from_bytes(bytes)? })
}
Expand All @@ -84,12 +85,14 @@ impl QrCodeData {
///
/// The list of bytes can be used by a QR code generator to create an image
/// containing a QR code.
#[wasm_bindgen(js_name = "toBytes")]
pub fn to_bytes(&self) -> Vec<u8> {
self.inner.to_bytes()
}

/// Attempt to decode a base64 encoded string into a {@link QrCodeData}
/// object.
#[wasm_bindgen(js_name = "fromBase64")]
pub fn from_base64(data: &str) -> Result<QrCodeData, JsError> {
Ok(Self { inner: qr_login::QrCodeData::from_base64(data)? })
}
Expand All @@ -99,6 +102,7 @@ impl QrCodeData {
/// This format can be used for debugging purposes and the
/// [`QrcodeData::from_base64()`] method can be used to parse the string
/// again.
#[wasm_bindgen(js_name = "toBase64")]
pub fn to_base64(&self) -> String {
self.inner.to_base64()
}
Expand All @@ -109,14 +113,14 @@ impl QrCodeData {
/// [ECIES](https://en.wikipedia.org/wiki/Integrated_Encryption_Scheme)
/// (Elliptic Curve Integrated Encryption Scheme) channel with the other
/// device.
#[wasm_bindgen(getter)]
#[wasm_bindgen(getter, js_name = "publicKey")]
pub fn public_key(&self) -> Curve25519PublicKey {
self.inner.public_key.into()
}

/// Get the URL of the rendezvous server which will be used to exchange
/// messages between the two devices.
#[wasm_bindgen(getter)]
#[wasm_bindgen(getter, js_name = "rendezvousUrl")]
pub fn rendezvous_url(&self) -> String {
self.inner.rendezvous_url.as_str().to_owned()
}
Expand All @@ -126,7 +130,7 @@ impl QrCodeData {
///
/// This will be only available if the existing device has generated the QR
/// code and the new device is the one scanning the QR code.
#[wasm_bindgen(getter)]
#[wasm_bindgen(getter, js_name = "serverName")]
pub fn server_name(&self) -> Option<String> {
if let qr_login::QrCodeModeData::Reciprocate { server_name } = &self.inner.mode_data {
Some(server_name.to_owned())
Expand Down
14 changes: 7 additions & 7 deletions tests/qr_code.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ describe(QrCodeData.name, () => {
const base64Data =
"TUFUUklYAgPYhmhqshl7eA4wCp1KIUdIBwDXkp85qzG55RQ3AkjtawBHaHR0cHM6Ly9yZW5kZXp2b3VzLmxhYi5lbGVtZW50LmRldi9lOGRhNjM1NS01NTBiLTRhMzItYTE5My0xNjE5ZDk4MzA2Njg";

const data = QrCodeData.from_base64(base64Data);
const data = QrCodeData.fromBase64(base64Data);

expect(data.public_key.toBase64()).toStrictEqual("2IZoarIZe3gOMAqdSiFHSAcA15KfOasxueUUNwJI7Ws");
expect(data.rendezvous_url).toStrictEqual(
expect(data.publicKey.toBase64()).toStrictEqual("2IZoarIZe3gOMAqdSiFHSAcA15KfOasxueUUNwJI7Ws");
expect(data.rendezvousUrl).toStrictEqual(
"https://rendezvous.lab.element.dev/e8da6355-550b-4a32-a193-1619d9830668",
);
expect(data.mode).toStrictEqual(QrCodeMode.Login);

const encoded = data.to_base64();
const encoded = data.toBase64();

expect(base64Data).toStrictEqual(encoded);
});
Expand All @@ -26,11 +26,11 @@ describe(QrCodeData.name, () => {

const data = new QrCodeData(publicKey, rendezvousUrl);

expect(data.public_key.toBase64()).toStrictEqual("2IZoarIZe3gOMAqdSiFHSAcA15KfOasxueUUNwJI7Ws");
expect(data.rendezvous_url).toStrictEqual(rendezvousUrl);
expect(data.publicKey.toBase64()).toStrictEqual("2IZoarIZe3gOMAqdSiFHSAcA15KfOasxueUUNwJI7Ws");
expect(data.rendezvousUrl).toStrictEqual(rendezvousUrl);
expect(data.mode).toStrictEqual(QrCodeMode.Login);

const encoded = data.to_base64();
const encoded = data.toBase64();
expect(base64Data).toStrictEqual(encoded);
});
});

0 comments on commit 0d58c68

Please sign in to comment.