Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
remove confusing copyright comment from file headers
Browse files Browse the repository at this point in the history
  • Loading branch information
btoews committed Jul 19, 2017
1 parent bb6a6f9 commit 0fd65a7
Show file tree
Hide file tree
Showing 61 changed files with 81 additions and 144 deletions.
3 changes: 0 additions & 3 deletions APDU/APDU.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// APDU
//
// Created by Benjamin P Toews on 2/7/17.
// Copyright © 2017 GitHub. All rights reserved.
//

#import <Cocoa/Cocoa.h>
Expand All @@ -15,5 +14,3 @@ FOUNDATION_EXPORT double APDUVersionNumber;
FOUNDATION_EXPORT const unsigned char APDUVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <APDU/PublicHeader.h>


1 change: 0 additions & 1 deletion APDU/AuthenticationRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 9/14/16.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand Down
11 changes: 5 additions & 6 deletions APDU/AuthenticationResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
// SoftU2F
//
// Created by Benjamin P Toews on 9/14/16.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation

public struct AuthenticationResponse: RawConvertible {
let body: Data
let trailer: ResponseStatus

public var userPresence: UInt8 {
return body[0]
}
Expand All @@ -20,7 +19,7 @@ public struct AuthenticationResponse: RawConvertible {
let lowerBound = MemoryLayout<UInt8>.size
let upperBound = lowerBound + MemoryLayout<UInt32>.size
let data = body.subdata(in: lowerBound..<upperBound)

return data.withUnsafeBytes { (ptr: UnsafePointer<UInt32>) -> UInt32 in
return ptr.pointee.bigEndian
}
Expand All @@ -37,7 +36,7 @@ public struct AuthenticationResponse: RawConvertible {
writer.write(userPresence)
writer.write(counter)
writer.writeData(signature)

body = writer.buffer
trailer = .NoError
}
Expand All @@ -48,13 +47,13 @@ extension AuthenticationResponse: Response {
self.body = body
self.trailer = trailer
}

func validateBody() throws {
// TODO: minimum signature size?
if body.count < MemoryLayout<UInt8>.size + MemoryLayout<UInt32>.size + 1 {
throw ResponseError.BadSize
}

if trailer != .NoError {
throw ResponseError.BadStatus
}
Expand Down
13 changes: 6 additions & 7 deletions APDU/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 2/7/17.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand All @@ -18,9 +17,9 @@ public protocol Command {
var header: CommandHeader { get }
var body: Data { get }
var trailer: CommandTrailer { get }

init(header: CommandHeader, body: Data, trailer: CommandTrailer)

func validateBody() throws
}

Expand All @@ -31,24 +30,24 @@ extension Command {
writer.writeData(header.raw)
writer.writeData(body)
writer.writeData(trailer.raw)

return writer.buffer
}

public init(raw: Data) throws {
let reader = DataReader(data: raw)
let header: CommandHeader
let body: Data
let trailer: CommandTrailer

do {
header = try CommandHeader(reader: reader)
body = try reader.readData(header.dataLength)
trailer = try CommandTrailer(reader: reader)
} catch DataReaderError.End {
throw ResponseStatus.WrongLength
}

self.init(header: header, body: body, trailer: trailer)

try validateBody()
Expand Down
3 changes: 1 addition & 2 deletions APDU/CommandHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 9/11/16.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand Down Expand Up @@ -64,7 +63,7 @@ public struct CommandHeader: RawConvertible, MessagePart {
throw ResponseStatus.WrongLength
}
}

init(cla: CommandClass = .Reserved, ins: CommandCode, p1: UInt8 = 0x00, p2: UInt8 = 0x00, dataLength: Int) {
self.cla = cla
self.ins = ins
Expand Down
3 changes: 1 addition & 2 deletions APDU/CommandTrailer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 1/25/17.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand Down Expand Up @@ -54,7 +53,7 @@ public struct CommandTrailer: RawConvertible, MessagePart {
throw ResponseStatus.WrongLength
}
}

init(noBody: Bool, maxResponse: Int = MaxResponseSize) {
self.noBody = noBody
self.maxResponse = maxResponse
Expand Down
5 changes: 2 additions & 3 deletions APDU/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 2/7/17.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand Down Expand Up @@ -31,15 +30,15 @@ public enum CommandCode: UInt8 {
public enum Control: UInt8 {
case EnforceUserPresenceAndSign = 0x03
case CheckOnly = 0x07

// Used internally.
case Invalid = 0xFF
}

// ISO7816-4
public enum ResponseStatus: UInt16, EndianEnumProtocol, Error {
public typealias RawValue = UInt16

case NoError = 0x9000
case WrongData = 0x6A80
case ConditionsNotSatisfied = 0x6985
Expand Down
1 change: 0 additions & 1 deletion APDU/Data/DataReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 9/11/16.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand Down
1 change: 0 additions & 1 deletion APDU/Data/DataWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 9/12/16.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand Down
1 change: 0 additions & 1 deletion APDU/Data/Endian.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 9/12/16.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand Down
3 changes: 1 addition & 2 deletions APDU/ErrorResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 1/26/17.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand All @@ -23,7 +22,7 @@ extension ErrorResponse: Response {
self.body = body
self.trailer = trailer
}

func validateBody() throws {
if body.count != 0 {
throw ResponseError.BadSize
Expand Down
1 change: 0 additions & 1 deletion APDU/MessagePart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 2/7/17.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand Down
1 change: 0 additions & 1 deletion APDU/RawConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 2/7/17.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand Down
7 changes: 3 additions & 4 deletions APDU/RegisterRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 9/10/16.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand All @@ -12,7 +11,7 @@ public struct RegisterRequest: RawConvertible {
public let header: CommandHeader
public let body: Data
public let trailer: CommandTrailer

public var challengeParameter: Data {
let lowerBound = 0
let upperBound = lowerBound + U2F_CHAL_SIZE
Expand All @@ -29,7 +28,7 @@ public struct RegisterRequest: RawConvertible {
let writer = DataWriter()
writer.writeData(challengeParameter)
writer.writeData(applicationParameter)

self.body = writer.buffer
self.header = CommandHeader(ins: .Register, dataLength: body.count)
self.trailer = CommandTrailer(noBody: false)
Expand All @@ -42,7 +41,7 @@ extension RegisterRequest: Command {
self.body = body
self.trailer = trailer
}

public func validateBody() throws {
if body.count != U2F_CHAL_SIZE + U2F_APPID_SIZE {
throw ResponseStatus.WrongLength
Expand Down
27 changes: 13 additions & 14 deletions APDU/RegisterResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SoftU2F
//
// Created by Benjamin P Toews on 9/11/16.
// Copyright © 2017 GitHub. All rights reserved.
//

import Foundation
Expand All @@ -16,19 +15,19 @@ public struct RegisterResponse: RawConvertible {
var reserved: UInt8 {
return body.subdata(in: reservedRange)[0]
}

public var publicKey: Data {
return body.subdata(in: publicKeyRange)
}

var keyHandleLength: Int {
return Int(body.subdata(in: keyHandleLengthRange)[0])
}

public var keyHandle: Data {
return body.subdata(in: keyHandleRange)
}

public var certificate: Data {
return body.subdata(in: certificateRange)
}
Expand All @@ -42,13 +41,13 @@ public struct RegisterResponse: RawConvertible {
let upperBound = MemoryLayout<UInt8>.size
return lowerBound..<upperBound
}

var publicKeyRange: Range<Int> {
let lowerBound = reservedRange.upperBound
let upperBound = lowerBound + U2F_EC_POINT_SIZE
return lowerBound..<upperBound
}

var keyHandleLengthRange: Range<Int> {
let lowerBound = publicKeyRange.upperBound
let upperBound = lowerBound + MemoryLayout<UInt8>.size
Expand All @@ -60,7 +59,7 @@ public struct RegisterResponse: RawConvertible {
let upperBound = lowerBound + keyHandleLength
return lowerBound..<upperBound
}

var certificateSize: Int {
let remainingRange: Range<Int> = keyHandleRange.upperBound..<body.count
let remaining = body.subdata(in: remainingRange)
Expand All @@ -72,19 +71,19 @@ public struct RegisterResponse: RawConvertible {
return 0
}
}

var certificateRange: Range<Int> {
let lowerBound = keyHandleRange.upperBound
let upperBound = lowerBound + certificateSize
return lowerBound..<upperBound
}

var signatureRange: Range<Int> {
let lowerBound = certificateRange.upperBound
let upperBound = body.count
return lowerBound..<upperBound
}

public init(publicKey: Data, keyHandle: Data, certificate: Data, signature: Data) {
let writer = DataWriter()
writer.write(UInt8(0x05)) // reserved
Expand All @@ -104,7 +103,7 @@ extension RegisterResponse: Response {
self.body = body
self.trailer = trailer
}

func validateBody() throws {
// Check that we at least have key-handle length.
var min = MemoryLayout<UInt8>.size + U2F_EC_POINT_SIZE + MemoryLayout<UInt8>.size
Expand All @@ -118,12 +117,12 @@ extension RegisterResponse: Response {
if body.count < min {
throw ResponseError.BadSize
}

// Check that cert is parsable.
if certificateSize == 0 {
throw ResponseError.BadCertificate
}

// Check that we at least have one byte of signature.
// TODO: minimum signature size?
min += certificateSize + 1
Expand All @@ -134,7 +133,7 @@ extension RegisterResponse: Response {
if reserved != 0x05 {
throw ResponseError.BadData
}

if trailer != .NoError {
throw ResponseError.BadStatus
}
Expand Down
Loading

0 comments on commit 0fd65a7

Please sign in to comment.