Enum matrix_qrcode::QrVerificationData
source · [−]pub enum QrVerificationData {
Verification(VerificationData),
SelfVerification(SelfVerificationData),
SelfVerificationNoMasterKey(SelfVerificationNoMasterKey),
}
Expand description
An enum representing the different modes a QR verification can be in.
Variants
Verification(VerificationData)
The QR verification is verifying another user
SelfVerification(SelfVerificationData)
The QR verification is self-verifying and the current device trusts or owns the master key
SelfVerificationNoMasterKey(SelfVerificationNoMasterKey)
The QR verification is self-verifying in which the current device does not yet trust the master key
Implementations
sourceimpl QrVerificationData
impl QrVerificationData
sourcepub fn from_image(
image: DynamicImage
) -> Result<QrVerificationData, DecodingError>
pub fn from_image(
image: DynamicImage
) -> Result<QrVerificationData, DecodingError>
Decode and parse an image of a QR code into a QrVerificationData
The image will be converted into a grey scale image before decoding is attempted
Arguments
image
- The image containing the QR code.
Example
use image;
let image = image::open("/path/to/my/image.png").unwrap();
let result = QrVerificationData::from_image(image)?;
sourcepub fn from_luma<I>(image: I) -> Result<QrVerificationData, DecodingError> where
I: GenericImage<Pixel = Luma<u8>, Pixel = Luma<u8>> + GenericImageView,
pub fn from_luma<I>(image: I) -> Result<QrVerificationData, DecodingError> where
I: GenericImage<Pixel = Luma<u8>, Pixel = Luma<u8>> + GenericImageView,
sourcepub fn from_bytes(
bytes: impl AsRef<[u8]>
) -> Result<QrVerificationData, DecodingError>
pub fn from_bytes(
bytes: impl AsRef<[u8]>
) -> Result<QrVerificationData, DecodingError>
Parse the decoded payload of a QR code in byte slice form as a
QrVerificationData
This method is useful if you would like to do your own custom QR code decoding.
Arguments
bytes
- The raw bytes of a decoded QR code.
Example
let data = b"MATRIX\
\x02\x02\x00\x07\
FLOW_ID\
kS /\x92i\x1e6\xcd'g\xf9#\x11\xd8\x8a\xa2\xf61\x05\x1b6\xef\xfc\xa4%\x80\x1a\x0c\xd2\xe8\x04\
\xbdR|\xf8n\x07\xa4\x1f\xb4\xcc3\x0eBT\xe7[~\xfd\x87\xd06B\xdfoVv%\x9b\x86\xae\xbcM\
SHARED_SECRET";
let result = QrVerificationData::from_bytes(data)?;
sourcepub fn to_qr_code(&self) -> Result<QrCode, EncodingError>
pub fn to_qr_code(&self) -> Result<QrCode, EncodingError>
Encode the QrVerificationData
into a QrCode
.
This method turns the QrVerificationData
into a QR code that can be
rendered and presented to be scanned.
The encoding can fail if the data doesn’t fit into a QR code or if the identity keys that should be encoded into the QR code are not valid base64.
Example
let data = b"MATRIX\
\x02\x02\x00\x07\
FLOW_ID\
kS /\x92i\x1e6\xcd'g\xf9#\x11\xd8\x8a\xa2\xf61\x05\x1b6\xef\xfc\xa4%\x80\x1a\x0c\xd2\xe8\x04\
\xbdR|\xf8n\x07\xa4\x1f\xb4\xcc3\x0eBT\xe7[~\xfd\x87\xd06B\xdfoVv%\x9b\x86\xae\xbcM\
SHARED_SECRET";
let result = QrVerificationData::from_bytes(data)?;
let encoded = result.to_qr_code().unwrap();
sourcepub fn to_bytes(&self) -> Result<Vec<u8, Global>, EncodingError>
pub fn to_bytes(&self) -> Result<Vec<u8, Global>, EncodingError>
Encode the QrVerificationData
into a vector of bytes that can be
encoded as a QR code.
The encoding can fail if the identity keys that should be encoded are not valid base64.
Example
let data = b"MATRIX\
\x02\x02\x00\x07\
FLOW_ID\
kS /\x92i\x1e6\xcd'g\xf9#\x11\xd8\x8a\xa2\xf61\x05\x1b6\xef\xfc\xa4%\x80\x1a\x0c\xd2\xe8\x04\
\xbdR|\xf8n\x07\xa4\x1f\xb4\xcc3\x0eBT\xe7[~\xfd\x87\xd06B\xdfoVv%\x9b\x86\xae\xbcM\
SHARED_SECRET";
let result = QrVerificationData::from_bytes(data)?;
let encoded = result.to_bytes().unwrap();
assert_eq!(data.as_ref(), encoded.as_slice());
sourcepub fn flow_id(&self) -> &str
pub fn flow_id(&self) -> &str
Get the flow id for this QrVerificationData
.
This represents the ID as a string even if it is a EventId
.
sourcepub fn second_key(&self) -> Ed25519PublicKey
pub fn second_key(&self) -> Ed25519PublicKey
Get the second key of this QrVerificationData
.
Trait Implementations
sourceimpl Clone for QrVerificationData
impl Clone for QrVerificationData
sourcefn clone(&self) -> QrVerificationData
fn clone(&self) -> QrVerificationData
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for QrVerificationData
impl Debug for QrVerificationData
sourceimpl From<SelfVerificationData> for QrVerificationData
impl From<SelfVerificationData> for QrVerificationData
sourcefn from(data: SelfVerificationData) -> QrVerificationData
fn from(data: SelfVerificationData) -> QrVerificationData
Converts to this type from the input type.
sourceimpl From<SelfVerificationNoMasterKey> for QrVerificationData
impl From<SelfVerificationNoMasterKey> for QrVerificationData
sourcefn from(data: SelfVerificationNoMasterKey) -> QrVerificationData
fn from(data: SelfVerificationNoMasterKey) -> QrVerificationData
Converts to this type from the input type.
sourceimpl From<VerificationData> for QrVerificationData
impl From<VerificationData> for QrVerificationData
sourcefn from(data: VerificationData) -> QrVerificationData
fn from(data: VerificationData) -> QrVerificationData
Converts to this type from the input type.
sourceimpl PartialEq<QrVerificationData> for QrVerificationData
impl PartialEq<QrVerificationData> for QrVerificationData
sourcefn eq(&self, other: &QrVerificationData) -> bool
fn eq(&self, other: &QrVerificationData) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &QrVerificationData) -> bool
fn ne(&self, other: &QrVerificationData) -> bool
This method tests for !=
.
sourceimpl<'_> TryFrom<&'_ [u8]> for QrVerificationData
impl<'_> TryFrom<&'_ [u8]> for QrVerificationData
type Error = DecodingError
type Error = DecodingError
The type returned in the event of a conversion error.
sourceimpl TryFrom<DynamicImage> for QrVerificationData
impl TryFrom<DynamicImage> for QrVerificationData
type Error = DecodingError
type Error = DecodingError
The type returned in the event of a conversion error.
sourcefn try_from(
image: DynamicImage
) -> Result<QrVerificationData, <QrVerificationData as TryFrom<DynamicImage>>::Error>
fn try_from(
image: DynamicImage
) -> Result<QrVerificationData, <QrVerificationData as TryFrom<DynamicImage>>::Error>
Performs the conversion.
sourceimpl TryFrom<ImageBuffer<Luma<u8>, Vec<u8, Global>>> for QrVerificationData
impl TryFrom<ImageBuffer<Luma<u8>, Vec<u8, Global>>> for QrVerificationData
type Error = DecodingError
type Error = DecodingError
The type returned in the event of a conversion error.
sourcefn try_from(
image: ImageBuffer<Luma<u8>, Vec<u8, Global>>
) -> Result<QrVerificationData, <QrVerificationData as TryFrom<ImageBuffer<Luma<u8>, Vec<u8, Global>>>>::Error>
fn try_from(
image: ImageBuffer<Luma<u8>, Vec<u8, Global>>
) -> Result<QrVerificationData, <QrVerificationData as TryFrom<ImageBuffer<Luma<u8>, Vec<u8, Global>>>>::Error>
Performs the conversion.
sourceimpl TryFrom<Vec<u8, Global>> for QrVerificationData
impl TryFrom<Vec<u8, Global>> for QrVerificationData
type Error = DecodingError
type Error = DecodingError
The type returned in the event of a conversion error.
impl StructuralPartialEq for QrVerificationData
Auto Trait Implementations
impl RefUnwindSafe for QrVerificationData
impl Send for QrVerificationData
impl Sync for QrVerificationData
impl Unpin for QrVerificationData
impl UnwindSafe for QrVerificationData
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more