.NET verifier SDK: Extraction
QrImage
Section titled “QrImage”Class in Verifiabl.Verifier.Extraction
An image’s pixels, for reading its Verifiabl QR code with Verifiabl..
Decode the image file with your own imaging library, then pass its pixels here: rows from top to bottom, tightly packed with no row padding. Alpha is not premultiplied; transparent pixels read as white. The SDK keeps a reference to the array, so do not change it while it is being read.
public sealed class QrImageInheritance: System.Object
MaxPixels
Section titled “MaxPixels”Field
The largest image the SDK reads: 50 megapixels, more than an A4 page scanned at 600 dpi.
public const int MaxPixels = 50000000Returns: System.Int32
Property
The image’s width in pixels.
public int Width { get; }Returns: System.Int32
Height
Section titled “Height”Property
The image’s height in pixels.
public int Height { get; }Returns: System.Int32
FromRgba32(byte[], int, int)
Section titled “FromRgba32(byte[], int, int)”Method
Pixels with 4 bytes each, in red, green, blue, alpha order.
public static QrImage FromRgba32(byte[] pixels, int width, int height)| Parameter | Type | Description |
|---|---|---|
pixels |
System. |
|
width |
System. |
|
height |
System. |
Returns: Verifiabl.Verifier.Extraction.QrImage
Exceptions
| Type | Condition |
|---|---|
System. |
The size is out of range or does not match the buffer. |
FromBgra32(byte[], int, int)
Section titled “FromBgra32(byte[], int, int)”Method
Pixels with 4 bytes each, in blue, green, red, alpha order, as Windows and Skia often store them.
public static QrImage FromBgra32(byte[] pixels, int width, int height)| Parameter | Type | Description |
|---|---|---|
pixels |
System. |
|
width |
System. |
|
height |
System. |
Returns: Verifiabl.Verifier.Extraction.QrImage
Exceptions
| Type | Condition |
|---|---|
System. |
The size is out of range or does not match the buffer. |
FromGray8(byte[], int, int)
Section titled “FromGray8(byte[], int, int)”Method
Greyscale pixels with 1 byte each.
public static QrImage FromGray8(byte[] pixels, int width, int height)| Parameter | Type | Description |
|---|---|---|
pixels |
System. |
|
width |
System. |
|
height |
System. |
Returns: Verifiabl.Verifier.Extraction.QrImage
Exceptions
| Type | Condition |
|---|---|
System. |
The size is out of range or does not match the buffer. |
QrPayloadReader
Section titled “QrPayloadReader”Class in Verifiabl.Verifier.Extraction
Reads the Verifiabl QR code in pixels that you decoded with your own imaging library.
The pixels are read in the WebAssembly sandbox with ZXing-C++, as an image file is, so a code reads the same from a file and from its pixels. Only QR codes shaped like a Verifiabl payload are read; other codes in the image are ignored. Scan links are never fetched and the text is returned unchanged.
The sandbox covers only the QR read. Your imaging library decodes the file
in your process, where the sandbox does not contain it. To decode an
untrusted file in the sandbox too, use
Verifiabl..
public static class QrPayloadReaderInheritance: System.Object
Read(QrImage, CancellationToken)
Section titled “Read(QrImage, CancellationToken)”Method
Read the QR code on the calling thread, without a time budget.
Copies of the same payload count once.
public static string? Read(QrImage image, CancellationToken cancellationToken = default)| Parameter | Type | Description |
|---|---|---|
image |
Verifiabl. |
The image’s pixels. |
cancellationToken |
System. |
Stops reading within about 50 milliseconds. |
Returns: System.String, The QR code text, unchanged, or null when the image has no readable Verifiabl QR code.
Exceptions
| Type | Condition |
|---|---|
Verifiabl. |
The image has two different Verifiabl QR codes, or reading it needs more memory or finds more QR code text than a payslip needs. |
System. |
cancellationToken was cancelled. |
System. |
Wasmtime’s native library could not be loaded. |
ReadAsync(QrImage, QrReadOptions?, CancellationToken)
Section titled “ReadAsync(QrImage, QrReadOptions?, CancellationToken)”Method
Read the QR code within Verifiabl..
Reading runs on the thread pool, at most one read for each processor at a
time across the process, and the sandbox stops it when the time budget
runs out. The budget starts once the sandbox’s module is compiled, which
the first read in a process waits for; see Verifiabl..
The pixels are copied into the sandbox when the read starts, so do not
change the array until the call ends. The call does not end while that
copy runs, so the array is yours again afterwards, whatever the outcome.
public static Task<string?> ReadAsync(QrImage image, QrReadOptions? options = null, CancellationToken cancellationToken = default)| Parameter | Type | Description |
|---|---|---|
image |
Verifiabl. |
The image’s pixels. |
options |
Verifiabl. |
Optional settings, such as the time budget. |
cancellationToken |
System. |
Cancels reading. |
Returns: System.Threading.Tasks.Task{System.String}, The QR code text, unchanged, or null when the image has no readable Verifiabl QR code.
Exceptions
| Type | Condition |
|---|---|
Verifiabl. |
The image has two different Verifiabl QR codes, reading it needs more memory or finds more QR code text than a payslip needs, or reading took longer than the time budget. |
System. |
cancellationToken was cancelled. |
System. |
Wasmtime’s native library could not be loaded. |
QrReadOptions
Section titled “QrReadOptions”Class in Verifiabl.Verifier.Extraction
Options for reading the QR code in an image’s pixels.
public sealed class QrReadOptionsInheritance: System.Object
Timeout
Section titled “Timeout”Property
Time budget for reading the pixels. Defaults to 30 seconds. It is
separate from Verifiabl., which covers
the verification call that follows.
public TimeSpan Timeout { get; set; }Returns: System.TimeSpan
SandboxModule
Section titled “SandboxModule”Class in Verifiabl.Verifier.Extraction
The WebAssembly module that reads every PDF, image file and pixel buffer.
The decoders run in a WebAssembly module that imports nothing, so they cannot open files, use the network or read the process’s memory. Each read gets a new instance, capped at 512 MiB, that stops soon after its time budget ends or its cancellation token is cancelled. A file that makes the decoders misbehave is reported as unreadable.
public static class SandboxModuleInheritance: System.Object
MaxFileBytes
Section titled “MaxFileBytes”Field
The largest file a reader accepts: 20 MiB.
public const int MaxFileBytes = 20971520Returns: System.Int32
LoadAsync(CancellationToken)
Section titled “LoadAsync(CancellationToken)”Method
Compile the module now, instead of during the first read.
The first use in a process compiles the module, which takes about 2 seconds
and longer on a busy machine. Later calls return at once. Each
ReadAsync and verify method awaits this before its time budget
starts, so the budget covers only the file. Call it at startup so the
first file does not wait.
public static Task LoadAsync(CancellationToken cancellationToken = default)| Parameter | Type | Description |
|---|---|---|
cancellationToken |
System. |
Ends the wait. Compiling continues, so a later call finds it done. |
Returns: System.Threading.Tasks.Task, A task that completes when the module is ready to read files.
Exceptions
| Type | Condition |
|---|---|
System. |
cancellationToken was cancelled. |
System. |
The sandbox itself could not start, such as when Wasmtime’s native library could not be loaded. |