Skip to content

Commit

Permalink
Merge pull request #226 from alexmoon/metadata-security
Browse files Browse the repository at this point in the history
Restore `Metadata::with_security` with a deprecation notice
  • Loading branch information
alexmoon authored Feb 1, 2024
2 parents 8ba471d + 7c211c0 commit bb169c0
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions nrf-softdevice/src/ble/gatt_server/characteristic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,36 @@ impl Metadata {
}
}

#[deprecated = "Use new(properties).security(write_security) instead."]
pub fn with_security(properties: Properties, write_security: SecurityMode) -> Self {
let cccd = if properties.indicate || properties.notify {
Some(AttributeMetadata::default().write_security(write_security))
} else {
None
};

let sccd = if properties.broadcast {
Some(AttributeMetadata::default().write_security(write_security))
} else {
None
};

Metadata {
properties,
cccd,
sccd,
..Default::default()
}
}

pub fn presentation(self, presentation: Presentation) -> Self {
let cpfd = Some(presentation);
Metadata { cpfd, ..self }
}

pub fn security(self, security: SecurityMode) -> Self {
let cccd = match self.cccd {
Some(cccd) => Some(cccd.write_security(security)),
None => None,
};

let sccd = match self.sccd {
Some(sccd) => Some(sccd.write_security(security)),
None => None,
};

pub fn security(self, write_security: SecurityMode) -> Self {
let cccd = self.cccd.map(|cccd| cccd.write_security(write_security));
let sccd = self.sccd.map(|sccd| sccd.write_security(write_security));
Metadata { cccd, sccd, ..self }
}
}

0 comments on commit bb169c0

Please sign in to comment.