Skip to main content

SignedMeterValue

Struct SignedMeterValue 

Source
pub struct SignedMeterValue {
    pub signed_meter_data: String,
    pub encoding_method: Option<String>,
    pub signing_method: Option<String>,
    pub public_key: Option<String>,
}
Expand description

A meter reading carrying the meter’s own digital signature.

Version-neutral: 2.x’s SignedMeterValueType and 1.6’s SignedData string both become this. The fields are carried through verbatim — the signature covers those exact bytes, so nothing here re-encodes, re-wraps or normalizes them.

Fields§

§signed_meter_data: String

signedMeterData: the signed record, Base64 as sent. An OCMF data set, an EDL file — whatever encoding_method names.

§encoding_method: Option<String>

encodingMethod: OCMF, EDL, …

Required by both 2.x schemas, so always Some there. A 1.6 SignedData payload may omit it; the record is still the billable one, so it is carried rather than refused — an OCMF data set announces itself with an OCMF| prefix in any case.

§signing_method: Option<String>

signingMethod: the signature algorithm, when it is not already inside the record.

§public_key: Option<String>

publicKey: the key the station claims signed the record.

Not key bytes — see public_key for the two shapes this field is actually sent in, and for why it is a claim rather than a binding.

Implementations§

Source§

impl SignedMeterValue

Source

pub fn new(signed_meter_data: impl Into<String>) -> Self

A signed meter value carrying just the record.

Source

pub fn with_encoding_method(self, method: impl Into<String>) -> Self

Sets encodingMethod.

Source

pub fn with_signing_method(self, method: impl Into<String>) -> Self

Sets signingMethod.

Source

pub fn with_public_key(self, key: impl Into<String>) -> Self

Sets publicKey.

Source

pub fn from_signed_data(value: &str) -> Result<Self, SignedDataError>

Parses the JSON document a 1.6 station puts in a SignedData sampled value.

§Errors

SignedDataError when the string is not the JSON object the application note describes.

Source

pub fn decoded(&self) -> Result<Vec<u8>, SignedDataError>

The record itself: the bytes the meter signed.

signedMeterData is specified as Base64 (2.0.1 Part 2 §2.46) and is usually sent that way. Stations that put the record in plain are common enough that refusing them is not an option — and the refusal would be a quiet one, because a station whose record “is not Base64” simply stops being billable for a reason nobody looks for.

The two can never collide, so both are read:

  • An OCMF record announces itself with the ASCII prefix OCMF|, and | is not in the Base64 alphabet. Nothing Base64 can start that way.
  • Anything else containing a character outside the Base64 alphabet is likewise not Base64 — an EDL record is XML, which starts <.
  • What is left is Base64 and is decoded.

Nothing is re-encoded on the way out: these are the bytes the signature covers.

§Errors

SignedDataError when the field is empty — an empty record is not a record.

Source

pub fn decoded_str(&self) -> Result<String, SignedDataError>

decoded as text.

OCMF is textual — a |-separated header, a JSON payload and a JSON signature — so this is what a consumer of an OCMF record actually wants. EDL is XML, also text.

§Errors

SignedDataError when the field is empty, or when the record is not UTF-8 — which means it is a binary format, and decoded is the right call for it.

Source

pub fn to_signed_data(&self) -> String

The JSON document a 1.6 station puts in a SignedData sampled value.

The inverse of v1_6::SampledValue::signed_meter_value, and the reason it is here rather than in every station: getting the shape right means knowing that 1.6 reuses 2.x’s type by serialising it into a string, which nothing in the 1.6 schema says. v1_6::SampledValue::signed wraps this together with the format the shape also requires.

Source

pub fn public_key(&self) -> Option<Result<PublicKey, PublicKeyError>>

The public key the station claims, in both shapes the field is sent in.

None when the station sent no key at all — which is normal: OCPP 2.x gates the field on the PublicKeyWithSignedMeterValue configuration variable, and a key that travels out of band is the stronger arrangement anyway.

§Errors

PublicKeyError when the field is not Base64, or is an oca: envelope this cannot read. See PublicKey for what the two shapes are and why there are two.

Source

pub fn public_key_bytes(&self) -> Option<Result<Vec<u8>, PublicKeyError>>

Just the key bytes — public_key without the provenance.

§Errors

As public_key.

Trait Implementations§

Source§

impl Clone for SignedMeterValue

Source§

fn clone(&self) -> SignedMeterValue

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SignedMeterValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SignedMeterValue

Source§

fn default() -> SignedMeterValue

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SignedMeterValue

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for SignedMeterValue

Source§

impl From<&SignedMeterValue> for SignedMeterValue

Source§

fn from(value: &SignedMeterValue) -> Self

Converts to this type from the input type.
Source§

impl From<&SignedMeterValue> for SignedMeterValue

Source§

fn from(value: &SignedMeterValue) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for SignedMeterValue

Source§

fn eq(&self, other: &SignedMeterValue) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for SignedMeterValue

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SignedMeterValue

Source§

impl TryFrom<&SignedMeterValue> for SignedMeterValue

Available on crate feature v2_0_1 only.
Source§

fn try_from(value: &SignedMeterValue) -> Result<Self, MissingField>

2.0.1 makes every member of SignedMeterValueType mandatory, so a value that came from 2.1 or from a 1.6 SignedData document may not fit — those two let a station omit the signing method and the public key.

Source§

type Error = MissingField

The type returned in the event of a conversion error.
Source§

impl TryFrom<&SignedMeterValue> for SignedMeterValue

Available on crate feature v2_1 only.
Source§

fn try_from(value: &SignedMeterValue) -> Result<Self, MissingField>

2.1 requires only the record and the method it is encoded in; the signing method and the public key became optional, because both can already be inside the record and the key is better obtained out of band.

Source§

type Error = MissingField

The type returned in the event of a conversion error.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.