Skip to content

Commit

Permalink
- Changed macAddress to be a var instead of a func, fixed typos…
Browse files Browse the repository at this point in the history
… in my commits from earlier today where I tested for "!= 0" instead of "== 0".
  • Loading branch information
wilshipley committed Nov 17, 2019
1 parent c29d716 commit ce50201
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions App Store Receipt Checker/MACAddress.swift
Expand Up @@ -13,14 +13,14 @@ import IOKit.network

public extension ProcessInfo {

func macAddress() -> [UInt8]? {
var macAddress: [UInt8]? {
// create matching services dictionary for IOKit to enumerate — this is some UGLY swift, since we're switching from and then back to `CFDictionary`s
guard var matchingDictionary = IOServiceMatching(kIOEthernetInterfaceClass) as? [String : CFTypeRef] else { return nil }
matchingDictionary[kIOPropertyMatchKey] = [kIOPrimaryInterface: true] as CFDictionary // there can be only one

// create ethernet iterator
var ioIterator = io_iterator_t(MACH_PORT_NULL)
guard IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary as CFDictionary, &ioIterator) != 0 else { return nil }
guard IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary as CFDictionary, &ioIterator) == noErr else { return nil }
if ioIterator == MACH_PORT_NULL { return nil } // "If NULL is returned, the iteration was successful but found no matching services."
defer { IOObjectRelease(ioIterator) }

Expand All @@ -31,7 +31,7 @@ public extension ProcessInfo {

// get that service's parent because the MAC address is there, for reasons
var parentService = io_object_t(MACH_PORT_NULL)
guard IORegistryEntryGetParentEntry(firstAndOnlyService, kIOServicePlane, &parentService) != 0 else { return nil }
guard IORegistryEntryGetParentEntry(firstAndOnlyService, kIOServicePlane, &parentService) == noErr else { return nil }
defer { IOObjectRelease(parentService) }

// finally, get the darn MAC
Expand Down
2 changes: 1 addition & 1 deletion App Store Receipt Checker/Store Receipts/Receipt.swift
Expand Up @@ -246,7 +246,7 @@ private extension Receipt { // MARK: private methods
}

private func checkReceiptHash() throws {
guard let macAddressBytes = ProcessInfo.processInfo.macAddress() else { throw Errors.cannotGetMacAddress }
guard let macAddressBytes = ProcessInfo.processInfo.macAddress else { throw Errors.cannotGetMacAddress }
guard let opaqueValueRawBytes = appReceiptEntries[.opaqueValue]?.rawValue.bytes else { throw Errors.receiptMalformedMissingOpaqueValue }
guard let bundleIdentifierRawBytes = appReceiptEntries[.bundleIdentifier]?.rawValue.bytes else { throw Errors.receiptMissingBundleIdentifier }

Expand Down

0 comments on commit ce50201

Please sign in to comment.