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: StringsignedMeterData: 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
impl SignedMeterValue
Sourcepub fn new(signed_meter_data: impl Into<String>) -> Self
pub fn new(signed_meter_data: impl Into<String>) -> Self
A signed meter value carrying just the record.
Sourcepub fn with_encoding_method(self, method: impl Into<String>) -> Self
pub fn with_encoding_method(self, method: impl Into<String>) -> Self
Sets encodingMethod.
Sourcepub fn with_signing_method(self, method: impl Into<String>) -> Self
pub fn with_signing_method(self, method: impl Into<String>) -> Self
Sets signingMethod.
Sourcepub fn with_public_key(self, key: impl Into<String>) -> Self
pub fn with_public_key(self, key: impl Into<String>) -> Self
Sets publicKey.
Sourcepub fn from_signed_data(value: &str) -> Result<Self, SignedDataError>
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.
Sourcepub fn decoded(&self) -> Result<Vec<u8>, SignedDataError>
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.
Sourcepub fn decoded_str(&self) -> Result<String, SignedDataError>
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.
Sourcepub fn to_signed_data(&self) -> String
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.
Sourcepub fn public_key(&self) -> Option<Result<PublicKey, PublicKeyError>>
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.
Sourcepub fn public_key_bytes(&self) -> Option<Result<Vec<u8>, PublicKeyError>>
pub fn public_key_bytes(&self) -> Option<Result<Vec<u8>, PublicKeyError>>
Trait Implementations§
Source§impl Clone for SignedMeterValue
impl Clone for SignedMeterValue
Source§fn clone(&self) -> SignedMeterValue
fn clone(&self) -> SignedMeterValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SignedMeterValue
impl Debug for SignedMeterValue
Source§impl Default for SignedMeterValue
impl Default for SignedMeterValue
Source§fn default() -> SignedMeterValue
fn default() -> SignedMeterValue
Source§impl<'de> Deserialize<'de> for SignedMeterValue
impl<'de> Deserialize<'de> for SignedMeterValue
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for SignedMeterValue
Source§impl From<&SignedMeterValue> for SignedMeterValue
impl From<&SignedMeterValue> for SignedMeterValue
Source§fn from(value: &SignedMeterValue) -> Self
fn from(value: &SignedMeterValue) -> Self
Source§impl From<&SignedMeterValue> for SignedMeterValue
impl From<&SignedMeterValue> for SignedMeterValue
Source§fn from(value: &SignedMeterValue) -> Self
fn from(value: &SignedMeterValue) -> Self
Source§impl PartialEq for SignedMeterValue
impl PartialEq for SignedMeterValue
Source§impl Serialize for SignedMeterValue
impl Serialize for SignedMeterValue
impl StructuralPartialEq for SignedMeterValue
Source§impl TryFrom<&SignedMeterValue> for SignedMeterValue
Available on crate feature v2_0_1 only.
impl TryFrom<&SignedMeterValue> for SignedMeterValue
v2_0_1 only.Source§fn try_from(value: &SignedMeterValue) -> Result<Self, MissingField>
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
type Error = MissingField
Source§impl TryFrom<&SignedMeterValue> for SignedMeterValue
Available on crate feature v2_1 only.
impl TryFrom<&SignedMeterValue> for SignedMeterValue
v2_1 only.Source§fn try_from(value: &SignedMeterValue) -> Result<Self, MissingField>
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.