Commit bda967b2 authored by Stefan van den Oord's avatar Stefan van den Oord

XdrReader for Announcement now checks that magic is correct

parent cf01987e
......@@ -35,7 +35,7 @@ public struct Announcement : XdrWritable, XdrReadable, Equatable {
/// XdrWritable
public func writeTo(writer: XdrWriter) {
writer.writeUInt32(Announcement.magic);
writer.writeUInt32(Announcement.magic)
writer.write(thisDevice)
writer.writeUInt32(UInt32(extraDevices.count))
for i in 0 ..< extraDevices.count {
......@@ -45,8 +45,9 @@ public struct Announcement : XdrWritable, XdrReadable, Equatable {
/// XdrReadable
public static func readFrom(reader: XdrReader) -> Announcement? {
if let _ = reader.readUInt32(),
let d = reader.read(Device.self),
guard let magic = reader.readUInt32() where magic == Announcement.magic else { return nil }
if let d = reader.read(Device.self),
let extraCount = reader.readUInt32()
{
var extra : [Device] = []
......
......@@ -236,6 +236,14 @@ class AnnouncementTests: QuickSpec {
let a = reader.read(Announcement.self)
expect(a).to(beNil())
}
fit("cannot read announcement with incorrect magic") {
var bytes = XdrWriter().write(someAnnouncementWithExtraDevices).xdrBytes
bytes[0]++
let reader = XdrReader(xdrBytes:bytes)
let a = reader.read(Announcement.self)
expect(a).to(beNil())
}
}
context("Equatable") {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment