pub(crate) fn verify_json(
        &self,
        user_id: &UserId,
        key_id: &DeviceKeyId,
        signing_key: &str,
        json: &mut Value,
    ) -> Result<(), SignatureError> {
        if key_id.algorithm() != DeviceKeyAlgorithm::Ed25519 {
            return Err(SignatureError::UnsupportedAlgorithm);
        }

        let json_object = json.as_object_mut().ok_or(SignatureError::NotAnObject)?;
        let unsigned = json_object.remove("unsigned");
        let signatures = json_object.remove("signatures");

        let canonical_json = cjson::to_string(json_object)?;

        if let Some(u) = unsigned {
            json_object.insert("unsigned".to_string(), u);
        }

        let signatures = signatures.ok_or(SignatureError::NoSignatureFound)?;
        let signature_object = signatures
            .as_object()
            .ok_or(SignatureError::NoSignatureFound)?;
        let signature = signature_object
            .get(user_id.as_str())
            .ok_or(SignatureError::NoSignatureFound)?;
        let signature = signature
            .get(key_id.to_string())
            .ok_or(SignatureError::NoSignatureFound)?;
        let signature = signature.as_str().ok_or(SignatureError::NoSignatureFound)?;

        let ret = if self
            .inner
            .ed25519_verify(signing_key, &canonical_json, signature)
            .is_ok()
        {
            Ok(())
        } else {
            Err(SignatureError::VerificationError)
        };

        json_object.insert("signatures".to_string(), signatures);

        ret
    }
/// Verify a signed JSON object.
///
/// The object must have a signatures key associated  with an object of the
/// form `user_id: {key_id: signature}`.
///
/// Returns Ok if the signature was successfully verified, otherwise an
/// SignatureError.
///
/// # Arguments
///
/// * `user_id` - The user who signed the JSON object.
///
/// * `key_id` - The id of the key that signed the JSON object.
///
/// * `signing_key` - The public ed25519 key which was used to sign the JSON
///     object.
///
/// * `json` - The JSON object that should be verified.
Verify a signed JSON object.
The object must have a signatures key associated  with an object of the
form `user_id: {key_id: signature}`.

Returns Ok if the signature was successfully verified, otherwise an
SignatureError.
Verify a signed JSON object . The object must have a signatures key associated with an object of the form ` user_id : { key_id : signature } ` . Returns Ok if the signature was successfully verified otherwise an SignatureError .
pub(crate) fn verify_json(
        &self,
        user_id: &UserId,
        key_id: &DeviceKeyId,
        signing_key: &str,
        json: &mut Value,
    ) -> Result<(), SignatureError> {
        if key_id.algorithm() != DeviceKeyAlgorithm::Ed25519 {
            return Err(SignatureError::UnsupportedAlgorithm);
        }
        let json_object = json.as_object_mut().ok_or(SignatureError::NotAnObject)?;
        let unsigned = json_object.remove("unsigned");
        let signatures = json_object.remove("signatures");
        let canonical_json = cjson::to_string(json_object)?;
        if let Some(u) = unsigned {
            json_object.insert("unsigned".to_string(), u);
        }
        let signatures = signatures.ok_or(SignatureError::NoSignatureFound)?;
        let signature_object = signatures
            .as_object()
            .ok_or(SignatureError::NoSignatureFound)?;
        let signature = signature_object
            .get(user_id.as_str())
            .ok_or(SignatureError::NoSignatureFound)?;
        let signature = signature
            .get(key_id.to_string())
            .ok_or(SignatureError::NoSignatureFound)?;
        let signature = signature.as_str().ok_or(SignatureError::NoSignatureFound)?;
        let ret = if self
            .inner
            .ed25519_verify(signing_key, &canonical_json, signature)
            .is_ok()
        {
            Ok(())
        } else {
            Err(SignatureError::VerificationError)
        };
        json_object.insert("signatures".to_string(), signatures);
        ret
    }
pub ( crate ) fn verify_json ( & self , user_id : & UserId , key_id : & DeviceKeyId , signing_key : & str , json : & mut Value , ) -> Result < ( ) , SignatureError > { if key_id . algorithm ( ) != DeviceKeyAlgorithm :: Ed25519 { return Err ( SignatureError :: UnsupportedAlgorithm ) ; } let json_object = json . as_object_mut ( ) . ok_or ( SignatureError :: NotAnObject ) ? ; let unsigned = json_object . remove ( " " ) ; let signatures = json_object . remove ( " " ) ; let canonical_json = cjson :: to_string ( json_object ) ? ; if let Some ( u ) = unsigned { json_object . insert ( " " . to_string ( ) , u ) ; } let signatures = signatures . ok_or ( SignatureError :: NoSignatureFound ) ? ; let signature_object = signatures . as_object ( ) . ok_or ( SignatureError :: NoSignatureFound ) ? ; let signature = signature_object . get ( user_id . as_str ( ) ) . ok_or ( SignatureError :: NoSignatureFound ) ? ; let signature = signature . get ( key_id . to_string ( ) ) . ok_or ( SignatureError :: NoSignatureFound ) ? ; let signature = signature . as_str ( ) . ok_or ( SignatureError :: NoSignatureFound ) ? ; let ret = if self . inner . ed25519_verify ( signing_key , & canonical_json , signature ) . is_ok ( ) { Ok ( ( ) ) } else { Err ( SignatureError :: VerificationError ) } ; json_object . insert ( " " . to_string ( ) , signatures ) ; ret }
Verify a signed JSON object.
Verify a signed JSON object .
&self
user_id
&UserId
key_id
&DeviceKeyId
signing_key
&str
json
&mut Value
&self
user_id
&UserId
key_id
&DeviceKeyId
signing_key
&str
json
&mut Value