id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
9,200 | brutella/hc | hap/secured_device.go | NewSecuredDevice | func NewSecuredDevice(name string, pin string, database db.Database) (SecuredDevice, error) {
d, err := NewDevice(name, database)
return &securedDevice{d, pin}, err
} | go | func NewSecuredDevice(name string, pin string, database db.Database) (SecuredDevice, error) {
d, err := NewDevice(name, database)
return &securedDevice{d, pin}, err
} | [
"func",
"NewSecuredDevice",
"(",
"name",
"string",
",",
"pin",
"string",
",",
"database",
"db",
".",
"Database",
")",
"(",
"SecuredDevice",
",",
"error",
")",
"{",
"d",
",",
"err",
":=",
"NewDevice",
"(",
"name",
",",
"database",
")",
"\n",
"return",
"&",
"securedDevice",
"{",
"d",
",",
"pin",
"}",
",",
"err",
"\n",
"}"
]
| // NewSecuredDevice returns a device for a specific name either loaded from the database or newly created.
// Additionally other device can only pair with by providing the correct pin. | [
"NewSecuredDevice",
"returns",
"a",
"device",
"for",
"a",
"specific",
"name",
"either",
"loaded",
"from",
"the",
"database",
"or",
"newly",
"created",
".",
"Additionally",
"other",
"device",
"can",
"only",
"pair",
"with",
"by",
"providing",
"the",
"correct",
"pin",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/secured_device.go#L20-L23 |
9,201 | brutella/hc | accessory/container.go | AddAccessory | func (m *Container) AddAccessory(a *Accessory) {
a.UpdateIDs()
a.SetID(m.idCount)
m.idCount++
m.Accessories = append(m.Accessories, a)
} | go | func (m *Container) AddAccessory(a *Accessory) {
a.UpdateIDs()
a.SetID(m.idCount)
m.idCount++
m.Accessories = append(m.Accessories, a)
} | [
"func",
"(",
"m",
"*",
"Container",
")",
"AddAccessory",
"(",
"a",
"*",
"Accessory",
")",
"{",
"a",
".",
"UpdateIDs",
"(",
")",
"\n",
"a",
".",
"SetID",
"(",
"m",
".",
"idCount",
")",
"\n",
"m",
".",
"idCount",
"++",
"\n",
"m",
".",
"Accessories",
"=",
"append",
"(",
"m",
".",
"Accessories",
",",
"a",
")",
"\n",
"}"
]
| // AddAccessory adds an accessory to the container.
// This method ensures that the accessory ids are valid and unique withing the container. | [
"AddAccessory",
"adds",
"an",
"accessory",
"to",
"the",
"container",
".",
"This",
"method",
"ensures",
"that",
"the",
"accessory",
"ids",
"are",
"valid",
"and",
"unique",
"withing",
"the",
"container",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/container.go#L26-L31 |
9,202 | brutella/hc | accessory/container.go | RemoveAccessory | func (m *Container) RemoveAccessory(a *Accessory) {
for i, accessory := range m.Accessories {
if accessory == a {
m.Accessories = append(m.Accessories[:i], m.Accessories[i+1:]...)
}
}
} | go | func (m *Container) RemoveAccessory(a *Accessory) {
for i, accessory := range m.Accessories {
if accessory == a {
m.Accessories = append(m.Accessories[:i], m.Accessories[i+1:]...)
}
}
} | [
"func",
"(",
"m",
"*",
"Container",
")",
"RemoveAccessory",
"(",
"a",
"*",
"Accessory",
")",
"{",
"for",
"i",
",",
"accessory",
":=",
"range",
"m",
".",
"Accessories",
"{",
"if",
"accessory",
"==",
"a",
"{",
"m",
".",
"Accessories",
"=",
"append",
"(",
"m",
".",
"Accessories",
"[",
":",
"i",
"]",
",",
"m",
".",
"Accessories",
"[",
"i",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // RemoveAccessory removes an accessory from the container. | [
"RemoveAccessory",
"removes",
"an",
"accessory",
"from",
"the",
"container",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/container.go#L34-L40 |
9,203 | brutella/hc | accessory/container.go | Equal | func (m *Container) Equal(other interface{}) bool {
if container, ok := other.(*Container); ok == true {
if len(m.Accessories) != len(container.Accessories) {
return false
}
for i, a := range m.Accessories {
if a.Equal(container.Accessories[i]) == false {
return false
}
}
return true
}
return false
} | go | func (m *Container) Equal(other interface{}) bool {
if container, ok := other.(*Container); ok == true {
if len(m.Accessories) != len(container.Accessories) {
return false
}
for i, a := range m.Accessories {
if a.Equal(container.Accessories[i]) == false {
return false
}
}
return true
}
return false
} | [
"func",
"(",
"m",
"*",
"Container",
")",
"Equal",
"(",
"other",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"container",
",",
"ok",
":=",
"other",
".",
"(",
"*",
"Container",
")",
";",
"ok",
"==",
"true",
"{",
"if",
"len",
"(",
"m",
".",
"Accessories",
")",
"!=",
"len",
"(",
"container",
".",
"Accessories",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"a",
":=",
"range",
"m",
".",
"Accessories",
"{",
"if",
"a",
".",
"Equal",
"(",
"container",
".",
"Accessories",
"[",
"i",
"]",
")",
"==",
"false",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
]
| // Equal returns true when receiver has the same accessories as the argument. | [
"Equal",
"returns",
"true",
"when",
"receiver",
"has",
"the",
"same",
"accessories",
"as",
"the",
"argument",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/container.go#L43-L58 |
9,204 | brutella/hc | accessory/container.go | AccessoryType | func (m *Container) AccessoryType() AccessoryType {
if as := m.Accessories; len(as) > 0 {
if len(as) > 1 {
return TypeBridge
}
return as[0].Type
}
return TypeOther
} | go | func (m *Container) AccessoryType() AccessoryType {
if as := m.Accessories; len(as) > 0 {
if len(as) > 1 {
return TypeBridge
}
return as[0].Type
}
return TypeOther
} | [
"func",
"(",
"m",
"*",
"Container",
")",
"AccessoryType",
"(",
")",
"AccessoryType",
"{",
"if",
"as",
":=",
"m",
".",
"Accessories",
";",
"len",
"(",
"as",
")",
">",
"0",
"{",
"if",
"len",
"(",
"as",
")",
">",
"1",
"{",
"return",
"TypeBridge",
"\n",
"}",
"\n\n",
"return",
"as",
"[",
"0",
"]",
".",
"Type",
"\n",
"}",
"\n\n",
"return",
"TypeOther",
"\n",
"}"
]
| // AccessoryType returns the accessory type identifier for the accessories inside the container. | [
"AccessoryType",
"returns",
"the",
"accessory",
"type",
"identifier",
"for",
"the",
"accessories",
"inside",
"the",
"container",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/container.go#L61-L71 |
9,205 | brutella/hc | hap/pair/setup_server_controller.go | NewSetupServerController | func NewSetupServerController(device hap.SecuredDevice, database db.Database) (*SetupServerController, error) {
if len(device.PrivateKey()) == 0 {
return nil, errors.New("no private key for pairing available")
}
session, err := NewSetupServerSession(device.Name(), device.Pin())
if err != nil {
return nil, err
}
controller := SetupServerController{
device: device,
session: session,
database: database,
step: PairStepWaiting,
}
return &controller, nil
} | go | func NewSetupServerController(device hap.SecuredDevice, database db.Database) (*SetupServerController, error) {
if len(device.PrivateKey()) == 0 {
return nil, errors.New("no private key for pairing available")
}
session, err := NewSetupServerSession(device.Name(), device.Pin())
if err != nil {
return nil, err
}
controller := SetupServerController{
device: device,
session: session,
database: database,
step: PairStepWaiting,
}
return &controller, nil
} | [
"func",
"NewSetupServerController",
"(",
"device",
"hap",
".",
"SecuredDevice",
",",
"database",
"db",
".",
"Database",
")",
"(",
"*",
"SetupServerController",
",",
"error",
")",
"{",
"if",
"len",
"(",
"device",
".",
"PrivateKey",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"session",
",",
"err",
":=",
"NewSetupServerSession",
"(",
"device",
".",
"Name",
"(",
")",
",",
"device",
".",
"Pin",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"controller",
":=",
"SetupServerController",
"{",
"device",
":",
"device",
",",
"session",
":",
"session",
",",
"database",
":",
"database",
",",
"step",
":",
"PairStepWaiting",
",",
"}",
"\n\n",
"return",
"&",
"controller",
",",
"nil",
"\n",
"}"
]
| // NewSetupServerController returns a new pair setup controller. | [
"NewSetupServerController",
"returns",
"a",
"new",
"pair",
"setup",
"controller",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/setup_server_controller.go#L31-L49 |
9,206 | brutella/hc | hap/endpoint/pair-verify.go | NewPairVerify | func NewPairVerify(context hap.Context, database db.Database) *PairVerify {
endpoint := PairVerify{
context: context,
database: database,
}
return &endpoint
} | go | func NewPairVerify(context hap.Context, database db.Database) *PairVerify {
endpoint := PairVerify{
context: context,
database: database,
}
return &endpoint
} | [
"func",
"NewPairVerify",
"(",
"context",
"hap",
".",
"Context",
",",
"database",
"db",
".",
"Database",
")",
"*",
"PairVerify",
"{",
"endpoint",
":=",
"PairVerify",
"{",
"context",
":",
"context",
",",
"database",
":",
"database",
",",
"}",
"\n\n",
"return",
"&",
"endpoint",
"\n",
"}"
]
| // NewPairVerify returns a new endpoint for pair verify endpoint | [
"NewPairVerify",
"returns",
"a",
"new",
"endpoint",
"for",
"pair",
"verify",
"endpoint"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/endpoint/pair-verify.go#L27-L34 |
9,207 | brutella/hc | hap/controller/container.go | HandleGetAccessories | func (ctr *ContainerController) HandleGetAccessories(r io.Reader) (io.Reader, error) {
result, err := json.Marshal(ctr.container)
return bytes.NewBuffer(result), err
} | go | func (ctr *ContainerController) HandleGetAccessories(r io.Reader) (io.Reader, error) {
result, err := json.Marshal(ctr.container)
return bytes.NewBuffer(result), err
} | [
"func",
"(",
"ctr",
"*",
"ContainerController",
")",
"HandleGetAccessories",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"io",
".",
"Reader",
",",
"error",
")",
"{",
"result",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"ctr",
".",
"container",
")",
"\n",
"return",
"bytes",
".",
"NewBuffer",
"(",
"result",
")",
",",
"err",
"\n",
"}"
]
| // HandleGetAccessories returns the container as json bytes. | [
"HandleGetAccessories",
"returns",
"the",
"container",
"as",
"json",
"bytes",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/controller/container.go#L21-L24 |
9,208 | brutella/hc | accessory/accessory.go | New | func New(info Info, typ AccessoryType) *Accessory {
svc := service.NewAccessoryInformation()
if name := info.Name; len(name) > 0 {
svc.Name.SetValue(name)
} else {
svc.Name.SetValue("undefined")
}
if serial := info.SerialNumber; len(serial) > 0 {
svc.SerialNumber.SetValue(serial)
} else {
svc.SerialNumber.SetValue("undefined")
}
if manufacturer := info.Manufacturer; len(manufacturer) > 0 {
svc.Manufacturer.SetValue(manufacturer)
} else {
svc.Manufacturer.SetValue("undefined")
}
if model := info.Model; len(model) > 0 {
svc.Model.SetValue(model)
} else {
svc.Model.SetValue("undefined")
}
if version := info.FirmwareRevision; len(version) > 0 {
svc.FirmwareRevision.SetValue(version)
} else {
svc.FirmwareRevision.SetValue("undefined")
}
acc := &Accessory{
idCount: 1,
Info: svc,
Type: typ,
}
acc.AddService(acc.Info.Service)
svc.Identify.OnValueRemoteUpdate(func(value bool) {
acc.Identify()
})
return acc
} | go | func New(info Info, typ AccessoryType) *Accessory {
svc := service.NewAccessoryInformation()
if name := info.Name; len(name) > 0 {
svc.Name.SetValue(name)
} else {
svc.Name.SetValue("undefined")
}
if serial := info.SerialNumber; len(serial) > 0 {
svc.SerialNumber.SetValue(serial)
} else {
svc.SerialNumber.SetValue("undefined")
}
if manufacturer := info.Manufacturer; len(manufacturer) > 0 {
svc.Manufacturer.SetValue(manufacturer)
} else {
svc.Manufacturer.SetValue("undefined")
}
if model := info.Model; len(model) > 0 {
svc.Model.SetValue(model)
} else {
svc.Model.SetValue("undefined")
}
if version := info.FirmwareRevision; len(version) > 0 {
svc.FirmwareRevision.SetValue(version)
} else {
svc.FirmwareRevision.SetValue("undefined")
}
acc := &Accessory{
idCount: 1,
Info: svc,
Type: typ,
}
acc.AddService(acc.Info.Service)
svc.Identify.OnValueRemoteUpdate(func(value bool) {
acc.Identify()
})
return acc
} | [
"func",
"New",
"(",
"info",
"Info",
",",
"typ",
"AccessoryType",
")",
"*",
"Accessory",
"{",
"svc",
":=",
"service",
".",
"NewAccessoryInformation",
"(",
")",
"\n\n",
"if",
"name",
":=",
"info",
".",
"Name",
";",
"len",
"(",
"name",
")",
">",
"0",
"{",
"svc",
".",
"Name",
".",
"SetValue",
"(",
"name",
")",
"\n",
"}",
"else",
"{",
"svc",
".",
"Name",
".",
"SetValue",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"serial",
":=",
"info",
".",
"SerialNumber",
";",
"len",
"(",
"serial",
")",
">",
"0",
"{",
"svc",
".",
"SerialNumber",
".",
"SetValue",
"(",
"serial",
")",
"\n",
"}",
"else",
"{",
"svc",
".",
"SerialNumber",
".",
"SetValue",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"manufacturer",
":=",
"info",
".",
"Manufacturer",
";",
"len",
"(",
"manufacturer",
")",
">",
"0",
"{",
"svc",
".",
"Manufacturer",
".",
"SetValue",
"(",
"manufacturer",
")",
"\n",
"}",
"else",
"{",
"svc",
".",
"Manufacturer",
".",
"SetValue",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"model",
":=",
"info",
".",
"Model",
";",
"len",
"(",
"model",
")",
">",
"0",
"{",
"svc",
".",
"Model",
".",
"SetValue",
"(",
"model",
")",
"\n",
"}",
"else",
"{",
"svc",
".",
"Model",
".",
"SetValue",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"version",
":=",
"info",
".",
"FirmwareRevision",
";",
"len",
"(",
"version",
")",
">",
"0",
"{",
"svc",
".",
"FirmwareRevision",
".",
"SetValue",
"(",
"version",
")",
"\n",
"}",
"else",
"{",
"svc",
".",
"FirmwareRevision",
".",
"SetValue",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"acc",
":=",
"&",
"Accessory",
"{",
"idCount",
":",
"1",
",",
"Info",
":",
"svc",
",",
"Type",
":",
"typ",
",",
"}",
"\n\n",
"acc",
".",
"AddService",
"(",
"acc",
".",
"Info",
".",
"Service",
")",
"\n\n",
"svc",
".",
"Identify",
".",
"OnValueRemoteUpdate",
"(",
"func",
"(",
"value",
"bool",
")",
"{",
"acc",
".",
"Identify",
"(",
")",
"\n",
"}",
")",
"\n\n",
"return",
"acc",
"\n",
"}"
]
| // New returns an accessory which implements model.Accessory. | [
"New",
"returns",
"an",
"accessory",
"which",
"implements",
"model",
".",
"Accessory",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/accessory.go#L32-L78 |
9,209 | brutella/hc | accessory/accessory.go | AddService | func (a *Accessory) AddService(s *service.Service) {
a.Services = append(a.Services, s)
} | go | func (a *Accessory) AddService(s *service.Service) {
a.Services = append(a.Services, s)
} | [
"func",
"(",
"a",
"*",
"Accessory",
")",
"AddService",
"(",
"s",
"*",
"service",
".",
"Service",
")",
"{",
"a",
".",
"Services",
"=",
"append",
"(",
"a",
".",
"Services",
",",
"s",
")",
"\n",
"}"
]
| // Adds a service to the accessory and updates the ids of the service and the corresponding characteristics | [
"Adds",
"a",
"service",
"to",
"the",
"accessory",
"and",
"updates",
"the",
"ids",
"of",
"the",
"service",
"and",
"the",
"corresponding",
"characteristics"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/accessory.go#L107-L109 |
9,210 | brutella/hc | accessory/accessory.go | UpdateIDs | func (a *Accessory) UpdateIDs() {
for _, s := range a.Services {
s.SetID(a.idCount)
a.idCount++
for _, c := range s.Characteristics {
c.SetID(a.idCount)
a.idCount++
}
}
} | go | func (a *Accessory) UpdateIDs() {
for _, s := range a.Services {
s.SetID(a.idCount)
a.idCount++
for _, c := range s.Characteristics {
c.SetID(a.idCount)
a.idCount++
}
}
} | [
"func",
"(",
"a",
"*",
"Accessory",
")",
"UpdateIDs",
"(",
")",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"a",
".",
"Services",
"{",
"s",
".",
"SetID",
"(",
"a",
".",
"idCount",
")",
"\n",
"a",
".",
"idCount",
"++",
"\n\n",
"for",
"_",
",",
"c",
":=",
"range",
"s",
".",
"Characteristics",
"{",
"c",
".",
"SetID",
"(",
"a",
".",
"idCount",
")",
"\n",
"a",
".",
"idCount",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // UpdateIDs updates the service and characteirstic ids. | [
"UpdateIDs",
"updates",
"the",
"service",
"and",
"characteirstic",
"ids",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/accessory.go#L112-L122 |
9,211 | brutella/hc | accessory/accessory.go | Equal | func (a *Accessory) Equal(other interface{}) bool {
if accessory, ok := other.(*Accessory); ok == true {
if len(a.Services) != len(accessory.Services) {
return false
}
for i, s := range a.Services {
if s.Equal(accessory.Services[i]) == false {
return false
}
}
return a.ID == accessory.ID
}
return false
} | go | func (a *Accessory) Equal(other interface{}) bool {
if accessory, ok := other.(*Accessory); ok == true {
if len(a.Services) != len(accessory.Services) {
return false
}
for i, s := range a.Services {
if s.Equal(accessory.Services[i]) == false {
return false
}
}
return a.ID == accessory.ID
}
return false
} | [
"func",
"(",
"a",
"*",
"Accessory",
")",
"Equal",
"(",
"other",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"accessory",
",",
"ok",
":=",
"other",
".",
"(",
"*",
"Accessory",
")",
";",
"ok",
"==",
"true",
"{",
"if",
"len",
"(",
"a",
".",
"Services",
")",
"!=",
"len",
"(",
"accessory",
".",
"Services",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"s",
":=",
"range",
"a",
".",
"Services",
"{",
"if",
"s",
".",
"Equal",
"(",
"accessory",
".",
"Services",
"[",
"i",
"]",
")",
"==",
"false",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"a",
".",
"ID",
"==",
"accessory",
".",
"ID",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
]
| // Equal returns true when receiver has the same services and id as the argument. | [
"Equal",
"returns",
"true",
"when",
"receiver",
"has",
"the",
"same",
"services",
"and",
"id",
"as",
"the",
"argument",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/accessory.go#L125-L141 |
9,212 | brutella/hc | ip_transport.go | isPaired | func (t *ipTransport) isPaired() bool {
// If more than one entity is stored in the database, we are paired with a device.
// The transport itself is a device and is stored in the database, therefore
// we have to check for more than one entity.
if es, err := t.database.Entities(); err == nil && len(es) > 1 {
return true
}
return false
} | go | func (t *ipTransport) isPaired() bool {
// If more than one entity is stored in the database, we are paired with a device.
// The transport itself is a device and is stored in the database, therefore
// we have to check for more than one entity.
if es, err := t.database.Entities(); err == nil && len(es) > 1 {
return true
}
return false
} | [
"func",
"(",
"t",
"*",
"ipTransport",
")",
"isPaired",
"(",
")",
"bool",
"{",
"// If more than one entity is stored in the database, we are paired with a device.",
"// The transport itself is a device and is stored in the database, therefore",
"// we have to check for more than one entity.",
"if",
"es",
",",
"err",
":=",
"t",
".",
"database",
".",
"Entities",
"(",
")",
";",
"err",
"==",
"nil",
"&&",
"len",
"(",
"es",
")",
">",
"1",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
]
| // isPaired returns true when the transport is already paired | [
"isPaired",
"returns",
"true",
"when",
"the",
"transport",
"is",
"already",
"paired"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/ip_transport.go#L211-L221 |
9,213 | brutella/hc | ip_transport.go | Handle | func (t *ipTransport) Handle(ev interface{}) {
switch ev.(type) {
case event.DevicePaired:
log.Debug.Printf("Event: paired with device")
t.updateMDNSReachability()
case event.DeviceUnpaired:
log.Debug.Printf("Event: unpaired with device")
t.updateMDNSReachability()
default:
break
}
} | go | func (t *ipTransport) Handle(ev interface{}) {
switch ev.(type) {
case event.DevicePaired:
log.Debug.Printf("Event: paired with device")
t.updateMDNSReachability()
case event.DeviceUnpaired:
log.Debug.Printf("Event: unpaired with device")
t.updateMDNSReachability()
default:
break
}
} | [
"func",
"(",
"t",
"*",
"ipTransport",
")",
"Handle",
"(",
"ev",
"interface",
"{",
"}",
")",
"{",
"switch",
"ev",
".",
"(",
"type",
")",
"{",
"case",
"event",
".",
"DevicePaired",
":",
"log",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"t",
".",
"updateMDNSReachability",
"(",
")",
"\n",
"case",
"event",
".",
"DeviceUnpaired",
":",
"log",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"t",
".",
"updateMDNSReachability",
"(",
")",
"\n",
"default",
":",
"break",
"\n",
"}",
"\n",
"}"
]
| // Handles event which are sent when pairing with a device is added or removed | [
"Handles",
"event",
"which",
"are",
"sent",
"when",
"pairing",
"with",
"a",
"device",
"is",
"added",
"or",
"removed"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/ip_transport.go#L278-L289 |
9,214 | brutella/hc | accessory/lightbulb.go | NewLightbulb | func NewLightbulb(info Info) *Lightbulb {
acc := Lightbulb{}
acc.Accessory = New(info, TypeLightbulb)
acc.Lightbulb = service.NewLightbulb()
acc.Lightbulb.Brightness.SetValue(100)
acc.AddService(acc.Lightbulb.Service)
return &acc
} | go | func NewLightbulb(info Info) *Lightbulb {
acc := Lightbulb{}
acc.Accessory = New(info, TypeLightbulb)
acc.Lightbulb = service.NewLightbulb()
acc.Lightbulb.Brightness.SetValue(100)
acc.AddService(acc.Lightbulb.Service)
return &acc
} | [
"func",
"NewLightbulb",
"(",
"info",
"Info",
")",
"*",
"Lightbulb",
"{",
"acc",
":=",
"Lightbulb",
"{",
"}",
"\n",
"acc",
".",
"Accessory",
"=",
"New",
"(",
"info",
",",
"TypeLightbulb",
")",
"\n",
"acc",
".",
"Lightbulb",
"=",
"service",
".",
"NewLightbulb",
"(",
")",
"\n\n",
"acc",
".",
"Lightbulb",
".",
"Brightness",
".",
"SetValue",
"(",
"100",
")",
"\n\n",
"acc",
".",
"AddService",
"(",
"acc",
".",
"Lightbulb",
".",
"Service",
")",
"\n\n",
"return",
"&",
"acc",
"\n",
"}"
]
| // NewLightbulb returns an light bulb accessory which one light bulb service. | [
"NewLightbulb",
"returns",
"an",
"light",
"bulb",
"accessory",
"which",
"one",
"light",
"bulb",
"service",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/lightbulb.go#L13-L23 |
9,215 | brutella/hc | termination.go | OnTermination | func OnTermination(fn TermFunc) {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
signal.Notify(c, os.Kill)
signal.Notify(c, syscall.SIGTERM)
go func() {
select {
case <-c:
if fn != nil {
fn()
}
}
}()
} | go | func OnTermination(fn TermFunc) {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
signal.Notify(c, os.Kill)
signal.Notify(c, syscall.SIGTERM)
go func() {
select {
case <-c:
if fn != nil {
fn()
}
}
}()
} | [
"func",
"OnTermination",
"(",
"fn",
"TermFunc",
")",
"{",
"c",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
")",
"\n",
"signal",
".",
"Notify",
"(",
"c",
",",
"os",
".",
"Interrupt",
")",
"\n",
"signal",
".",
"Notify",
"(",
"c",
",",
"os",
".",
"Kill",
")",
"\n",
"signal",
".",
"Notify",
"(",
"c",
",",
"syscall",
".",
"SIGTERM",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"select",
"{",
"case",
"<-",
"c",
":",
"if",
"fn",
"!=",
"nil",
"{",
"fn",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"}"
]
| // OnTermination calls a function when the app receives an interrupt of kill signal. | [
"OnTermination",
"calls",
"a",
"function",
"when",
"the",
"app",
"receives",
"an",
"interrupt",
"of",
"kill",
"signal",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/termination.go#L13-L27 |
9,216 | brutella/hc | util/mac.go | MAC48Address | func MAC48Address(input string) string {
h := md5.New()
h.Write([]byte(input))
result := h.Sum(nil)
var c []string
c = append(c, toHex(result[0]))
c = append(c, toHex(result[1]))
c = append(c, toHex(result[2]))
c = append(c, toHex(result[3]))
c = append(c, toHex(result[4]))
c = append(c, toHex(result[5]))
return strings.ToUpper(strings.Join(c, ":"))
} | go | func MAC48Address(input string) string {
h := md5.New()
h.Write([]byte(input))
result := h.Sum(nil)
var c []string
c = append(c, toHex(result[0]))
c = append(c, toHex(result[1]))
c = append(c, toHex(result[2]))
c = append(c, toHex(result[3]))
c = append(c, toHex(result[4]))
c = append(c, toHex(result[5]))
return strings.ToUpper(strings.Join(c, ":"))
} | [
"func",
"MAC48Address",
"(",
"input",
"string",
")",
"string",
"{",
"h",
":=",
"md5",
".",
"New",
"(",
")",
"\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"input",
")",
")",
"\n",
"result",
":=",
"h",
".",
"Sum",
"(",
"nil",
")",
"\n\n",
"var",
"c",
"[",
"]",
"string",
"\n",
"c",
"=",
"append",
"(",
"c",
",",
"toHex",
"(",
"result",
"[",
"0",
"]",
")",
")",
"\n",
"c",
"=",
"append",
"(",
"c",
",",
"toHex",
"(",
"result",
"[",
"1",
"]",
")",
")",
"\n",
"c",
"=",
"append",
"(",
"c",
",",
"toHex",
"(",
"result",
"[",
"2",
"]",
")",
")",
"\n",
"c",
"=",
"append",
"(",
"c",
",",
"toHex",
"(",
"result",
"[",
"3",
"]",
")",
")",
"\n",
"c",
"=",
"append",
"(",
"c",
",",
"toHex",
"(",
"result",
"[",
"4",
"]",
")",
")",
"\n",
"c",
"=",
"append",
"(",
"c",
",",
"toHex",
"(",
"result",
"[",
"5",
"]",
")",
")",
"\n\n",
"return",
"strings",
".",
"ToUpper",
"(",
"strings",
".",
"Join",
"(",
"c",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
]
| // MAC48Address returns a MAC-48-like address from the argument string | [
"MAC48Address",
"returns",
"a",
"MAC",
"-",
"48",
"-",
"like",
"address",
"from",
"the",
"argument",
"string"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/util/mac.go#L10-L24 |
9,217 | brutella/hc | hap/notification.go | NewCharacteristicNotification | func NewCharacteristicNotification(a *accessory.Accessory, c *characteristic.Characteristic) (*http.Response, error) {
body, err := Body(a, c)
if err != nil {
return nil, err
}
return NewNotification(body), nil
} | go | func NewCharacteristicNotification(a *accessory.Accessory, c *characteristic.Characteristic) (*http.Response, error) {
body, err := Body(a, c)
if err != nil {
return nil, err
}
return NewNotification(body), nil
} | [
"func",
"NewCharacteristicNotification",
"(",
"a",
"*",
"accessory",
".",
"Accessory",
",",
"c",
"*",
"characteristic",
".",
"Characteristic",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"Body",
"(",
"a",
",",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"NewNotification",
"(",
"body",
")",
",",
"nil",
"\n",
"}"
]
| // NewCharacteristicNotification returns an notification response for a characteristic from an accessory. | [
"NewCharacteristicNotification",
"returns",
"an",
"notification",
"response",
"for",
"a",
"characteristic",
"from",
"an",
"accessory",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/notification.go#L15-L22 |
9,218 | brutella/hc | hap/notification.go | NewNotification | func NewNotification(body *bytes.Buffer) *http.Response {
resp := new(http.Response)
resp.Status = "200 OK"
resp.StatusCode = http.StatusOK
resp.ProtoMajor = 1
resp.ProtoMinor = 0
resp.Body = ioutil.NopCloser(body)
resp.ContentLength = int64(body.Len())
resp.Header = map[string][]string{}
resp.Header.Set("Content-Type", HTTPContentTypeHAPJson)
// Will be ignored unfortunately and won't be fixed https://github.com/golang/go/issues/9304
// Make sure to call FixProtocolSpecifier() instead
resp.Proto = "EVENT/1.0"
return resp
} | go | func NewNotification(body *bytes.Buffer) *http.Response {
resp := new(http.Response)
resp.Status = "200 OK"
resp.StatusCode = http.StatusOK
resp.ProtoMajor = 1
resp.ProtoMinor = 0
resp.Body = ioutil.NopCloser(body)
resp.ContentLength = int64(body.Len())
resp.Header = map[string][]string{}
resp.Header.Set("Content-Type", HTTPContentTypeHAPJson)
// Will be ignored unfortunately and won't be fixed https://github.com/golang/go/issues/9304
// Make sure to call FixProtocolSpecifier() instead
resp.Proto = "EVENT/1.0"
return resp
} | [
"func",
"NewNotification",
"(",
"body",
"*",
"bytes",
".",
"Buffer",
")",
"*",
"http",
".",
"Response",
"{",
"resp",
":=",
"new",
"(",
"http",
".",
"Response",
")",
"\n",
"resp",
".",
"Status",
"=",
"\"",
"\"",
"\n",
"resp",
".",
"StatusCode",
"=",
"http",
".",
"StatusOK",
"\n",
"resp",
".",
"ProtoMajor",
"=",
"1",
"\n",
"resp",
".",
"ProtoMinor",
"=",
"0",
"\n",
"resp",
".",
"Body",
"=",
"ioutil",
".",
"NopCloser",
"(",
"body",
")",
"\n",
"resp",
".",
"ContentLength",
"=",
"int64",
"(",
"body",
".",
"Len",
"(",
")",
")",
"\n",
"resp",
".",
"Header",
"=",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"}",
"\n",
"resp",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"HTTPContentTypeHAPJson",
")",
"\n\n",
"// Will be ignored unfortunately and won't be fixed https://github.com/golang/go/issues/9304",
"// Make sure to call FixProtocolSpecifier() instead",
"resp",
".",
"Proto",
"=",
"\"",
"\"",
"\n\n",
"return",
"resp",
"\n",
"}"
]
| // NewNotification returns a notification response with a specific body content. | [
"NewNotification",
"returns",
"a",
"notification",
"response",
"with",
"a",
"specific",
"body",
"content",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/notification.go#L25-L41 |
9,219 | brutella/hc | hap/notification.go | Body | func Body(a *accessory.Accessory, c *characteristic.Characteristic) (*bytes.Buffer, error) {
ch := data.Characteristic{AccessoryID: a.GetID(), CharacteristicID: c.GetID(), Value: c.Value}
chars := data.Characteristics{[]data.Characteristic{ch}}
result, err := json.Marshal(chars)
if err != nil {
return nil, err
}
var b bytes.Buffer
b.Write(result)
return &b, err
} | go | func Body(a *accessory.Accessory, c *characteristic.Characteristic) (*bytes.Buffer, error) {
ch := data.Characteristic{AccessoryID: a.GetID(), CharacteristicID: c.GetID(), Value: c.Value}
chars := data.Characteristics{[]data.Characteristic{ch}}
result, err := json.Marshal(chars)
if err != nil {
return nil, err
}
var b bytes.Buffer
b.Write(result)
return &b, err
} | [
"func",
"Body",
"(",
"a",
"*",
"accessory",
".",
"Accessory",
",",
"c",
"*",
"characteristic",
".",
"Characteristic",
")",
"(",
"*",
"bytes",
".",
"Buffer",
",",
"error",
")",
"{",
"ch",
":=",
"data",
".",
"Characteristic",
"{",
"AccessoryID",
":",
"a",
".",
"GetID",
"(",
")",
",",
"CharacteristicID",
":",
"c",
".",
"GetID",
"(",
")",
",",
"Value",
":",
"c",
".",
"Value",
"}",
"\n",
"chars",
":=",
"data",
".",
"Characteristics",
"{",
"[",
"]",
"data",
".",
"Characteristic",
"{",
"ch",
"}",
"}",
"\n",
"result",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"chars",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"b",
".",
"Write",
"(",
"result",
")",
"\n",
"return",
"&",
"b",
",",
"err",
"\n",
"}"
]
| // Body returns the json body for an notification response as bytes. | [
"Body",
"returns",
"the",
"json",
"body",
"for",
"an",
"notification",
"response",
"as",
"bytes",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/notification.go#L52-L64 |
9,220 | brutella/hc | crypto/hkdf/hkdf.go | Sha512 | func Sha512(master, salt, info []byte) ([32]byte, error) {
hash := sha512.New
hkdf := hkdf.New(hash, master, salt, info)
key := make([]byte, 32) // 256 bit
_, err := io.ReadFull(hkdf, key)
var result [32]byte
copy(result[:], key)
return result, err
} | go | func Sha512(master, salt, info []byte) ([32]byte, error) {
hash := sha512.New
hkdf := hkdf.New(hash, master, salt, info)
key := make([]byte, 32) // 256 bit
_, err := io.ReadFull(hkdf, key)
var result [32]byte
copy(result[:], key)
return result, err
} | [
"func",
"Sha512",
"(",
"master",
",",
"salt",
",",
"info",
"[",
"]",
"byte",
")",
"(",
"[",
"32",
"]",
"byte",
",",
"error",
")",
"{",
"hash",
":=",
"sha512",
".",
"New",
"\n",
"hkdf",
":=",
"hkdf",
".",
"New",
"(",
"hash",
",",
"master",
",",
"salt",
",",
"info",
")",
"\n\n",
"key",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"32",
")",
"// 256 bit",
"\n",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"hkdf",
",",
"key",
")",
"\n\n",
"var",
"result",
"[",
"32",
"]",
"byte",
"\n",
"copy",
"(",
"result",
"[",
":",
"]",
",",
"key",
")",
"\n\n",
"return",
"result",
",",
"err",
"\n",
"}"
]
| // Sha512 returns a 256-bit key | [
"Sha512",
"returns",
"a",
"256",
"-",
"bit",
"key"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/crypto/hkdf/hkdf.go#L10-L21 |
9,221 | brutella/hc | hap/endpoint/accessories.go | NewAccessories | func NewAccessories(c hap.AccessoriesHandler, mutex *sync.Mutex) *Accessories {
handler := Accessories{
controller: c,
mutex: mutex,
}
return &handler
} | go | func NewAccessories(c hap.AccessoriesHandler, mutex *sync.Mutex) *Accessories {
handler := Accessories{
controller: c,
mutex: mutex,
}
return &handler
} | [
"func",
"NewAccessories",
"(",
"c",
"hap",
".",
"AccessoriesHandler",
",",
"mutex",
"*",
"sync",
".",
"Mutex",
")",
"*",
"Accessories",
"{",
"handler",
":=",
"Accessories",
"{",
"controller",
":",
"c",
",",
"mutex",
":",
"mutex",
",",
"}",
"\n\n",
"return",
"&",
"handler",
"\n",
"}"
]
| // NewAccessories returns a new handler for accessories endpoint | [
"NewAccessories",
"returns",
"a",
"new",
"handler",
"for",
"accessories",
"endpoint"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/endpoint/accessories.go#L24-L31 |
9,222 | brutella/hc | util/tlv8.go | NewTLV8ContainerFromReader | func NewTLV8ContainerFromReader(r io.Reader) (Container, error) {
var items = make([]tlv8, 0, 1)
for r != nil {
var item tlv8
if err := binary.Read(r, binary.LittleEndian, &item.tag); err != nil {
if err == io.EOF {
break
}
return nil, err
}
if err := binary.Read(r, binary.LittleEndian, &item.length); err != nil {
return nil, err
}
item.value = make([]byte, item.length)
if err := binary.Read(r, binary.LittleEndian, &item.value); err != nil {
return nil, err
}
items = append(items, item)
}
return &tlv8Container{
Items: items,
}, nil
} | go | func NewTLV8ContainerFromReader(r io.Reader) (Container, error) {
var items = make([]tlv8, 0, 1)
for r != nil {
var item tlv8
if err := binary.Read(r, binary.LittleEndian, &item.tag); err != nil {
if err == io.EOF {
break
}
return nil, err
}
if err := binary.Read(r, binary.LittleEndian, &item.length); err != nil {
return nil, err
}
item.value = make([]byte, item.length)
if err := binary.Read(r, binary.LittleEndian, &item.value); err != nil {
return nil, err
}
items = append(items, item)
}
return &tlv8Container{
Items: items,
}, nil
} | [
"func",
"NewTLV8ContainerFromReader",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"Container",
",",
"error",
")",
"{",
"var",
"items",
"=",
"make",
"(",
"[",
"]",
"tlv8",
",",
"0",
",",
"1",
")",
"\n",
"for",
"r",
"!=",
"nil",
"{",
"var",
"item",
"tlv8",
"\n",
"if",
"err",
":=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"item",
".",
"tag",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"break",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"item",
".",
"length",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"item",
".",
"value",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"item",
".",
"length",
")",
"\n",
"if",
"err",
":=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"item",
".",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"items",
"=",
"append",
"(",
"items",
",",
"item",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"tlv8Container",
"{",
"Items",
":",
"items",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // NewTLV8ContainerFromReader returns a tlv8 container from a bytes buffer. | [
"NewTLV8ContainerFromReader",
"returns",
"a",
"tlv8",
"container",
"from",
"a",
"bytes",
"buffer",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/util/tlv8.go#L25-L50 |
9,223 | brutella/hc | hap/session.go | NewSession | func NewSession(connection net.Conn) Session {
s := session{
connection: connection,
}
return &s
} | go | func NewSession(connection net.Conn) Session {
s := session{
connection: connection,
}
return &s
} | [
"func",
"NewSession",
"(",
"connection",
"net",
".",
"Conn",
")",
"Session",
"{",
"s",
":=",
"session",
"{",
"connection",
":",
"connection",
",",
"}",
"\n\n",
"return",
"&",
"s",
"\n",
"}"
]
| // NewSession returns a session for a connection. | [
"NewSession",
"returns",
"a",
"session",
"for",
"a",
"connection",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/session.go#L46-L52 |
9,224 | brutella/hc | accessory/outlet.go | NewOutlet | func NewOutlet(info Info) *Outlet {
acc := Outlet{}
acc.Accessory = New(info, TypeOutlet)
acc.Outlet = service.NewOutlet()
acc.Outlet.OutletInUse.SetValue(true)
acc.AddService(acc.Outlet.Service)
return &acc
} | go | func NewOutlet(info Info) *Outlet {
acc := Outlet{}
acc.Accessory = New(info, TypeOutlet)
acc.Outlet = service.NewOutlet()
acc.Outlet.OutletInUse.SetValue(true)
acc.AddService(acc.Outlet.Service)
return &acc
} | [
"func",
"NewOutlet",
"(",
"info",
"Info",
")",
"*",
"Outlet",
"{",
"acc",
":=",
"Outlet",
"{",
"}",
"\n",
"acc",
".",
"Accessory",
"=",
"New",
"(",
"info",
",",
"TypeOutlet",
")",
"\n",
"acc",
".",
"Outlet",
"=",
"service",
".",
"NewOutlet",
"(",
")",
"\n",
"acc",
".",
"Outlet",
".",
"OutletInUse",
".",
"SetValue",
"(",
"true",
")",
"\n\n",
"acc",
".",
"AddService",
"(",
"acc",
".",
"Outlet",
".",
"Service",
")",
"\n\n",
"return",
"&",
"acc",
"\n",
"}"
]
| // NewOutlet returns an outlet accessory containing one outlet service. | [
"NewOutlet",
"returns",
"an",
"outlet",
"accessory",
"containing",
"one",
"outlet",
"service",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/outlet.go#L13-L22 |
9,225 | brutella/hc | hap/endpoint/pairings.go | NewPairing | func NewPairing(controller *pair.PairingController, emitter event.Emitter) *Pairing {
endpoint := Pairing{
controller: controller,
emitter: emitter,
}
return &endpoint
} | go | func NewPairing(controller *pair.PairingController, emitter event.Emitter) *Pairing {
endpoint := Pairing{
controller: controller,
emitter: emitter,
}
return &endpoint
} | [
"func",
"NewPairing",
"(",
"controller",
"*",
"pair",
".",
"PairingController",
",",
"emitter",
"event",
".",
"Emitter",
")",
"*",
"Pairing",
"{",
"endpoint",
":=",
"Pairing",
"{",
"controller",
":",
"controller",
",",
"emitter",
":",
"emitter",
",",
"}",
"\n\n",
"return",
"&",
"endpoint",
"\n",
"}"
]
| // NewPairing returns a new handler for pairing enpdoint | [
"NewPairing",
"returns",
"a",
"new",
"handler",
"for",
"pairing",
"enpdoint"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/endpoint/pairings.go#L24-L31 |
9,226 | brutella/hc | hap/pair/pairing_controller.go | NewPairingController | func NewPairingController(database db.Database) *PairingController {
c := PairingController{
database: database,
}
return &c
} | go | func NewPairingController(database db.Database) *PairingController {
c := PairingController{
database: database,
}
return &c
} | [
"func",
"NewPairingController",
"(",
"database",
"db",
".",
"Database",
")",
"*",
"PairingController",
"{",
"c",
":=",
"PairingController",
"{",
"database",
":",
"database",
",",
"}",
"\n\n",
"return",
"&",
"c",
"\n",
"}"
]
| // NewPairingController returns a pairing controller. | [
"NewPairingController",
"returns",
"a",
"pairing",
"controller",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/pairing_controller.go#L17-L23 |
9,227 | brutella/hc | hap/pair/pairing_controller.go | Handle | func (c *PairingController) Handle(cont util.Container) (util.Container, error) {
method := PairMethodType(cont.GetByte(TagPairingMethod))
perm := cont.GetByte(TagPermission)
username := cont.GetString(TagUsername)
publicKey := cont.GetBytes(TagPublicKey)
log.Debug.Println("-> Method:", method)
log.Debug.Println("-> Permission:", perm)
log.Debug.Println("-> Username:", username)
log.Debug.Println("-> LTPK:", publicKey)
entity := db.NewEntity(username, publicKey, nil)
out := util.NewTLV8Container()
out.SetByte(TagSequence, 0x2)
switch method {
case PairingMethodDelete:
log.Debug.Printf("Remove LTPK for client '%s'\n", username)
c.database.DeleteEntity(entity)
case PairingMethodAdd:
err := c.database.SaveEntity(entity)
if err != nil {
log.Info.Panic(err)
return nil, err
}
default:
return nil, fmt.Errorf("Invalid pairing method type %v", method)
}
return out, nil
} | go | func (c *PairingController) Handle(cont util.Container) (util.Container, error) {
method := PairMethodType(cont.GetByte(TagPairingMethod))
perm := cont.GetByte(TagPermission)
username := cont.GetString(TagUsername)
publicKey := cont.GetBytes(TagPublicKey)
log.Debug.Println("-> Method:", method)
log.Debug.Println("-> Permission:", perm)
log.Debug.Println("-> Username:", username)
log.Debug.Println("-> LTPK:", publicKey)
entity := db.NewEntity(username, publicKey, nil)
out := util.NewTLV8Container()
out.SetByte(TagSequence, 0x2)
switch method {
case PairingMethodDelete:
log.Debug.Printf("Remove LTPK for client '%s'\n", username)
c.database.DeleteEntity(entity)
case PairingMethodAdd:
err := c.database.SaveEntity(entity)
if err != nil {
log.Info.Panic(err)
return nil, err
}
default:
return nil, fmt.Errorf("Invalid pairing method type %v", method)
}
return out, nil
} | [
"func",
"(",
"c",
"*",
"PairingController",
")",
"Handle",
"(",
"cont",
"util",
".",
"Container",
")",
"(",
"util",
".",
"Container",
",",
"error",
")",
"{",
"method",
":=",
"PairMethodType",
"(",
"cont",
".",
"GetByte",
"(",
"TagPairingMethod",
")",
")",
"\n",
"perm",
":=",
"cont",
".",
"GetByte",
"(",
"TagPermission",
")",
"\n",
"username",
":=",
"cont",
".",
"GetString",
"(",
"TagUsername",
")",
"\n",
"publicKey",
":=",
"cont",
".",
"GetBytes",
"(",
"TagPublicKey",
")",
"\n\n",
"log",
".",
"Debug",
".",
"Println",
"(",
"\"",
"\"",
",",
"method",
")",
"\n",
"log",
".",
"Debug",
".",
"Println",
"(",
"\"",
"\"",
",",
"perm",
")",
"\n",
"log",
".",
"Debug",
".",
"Println",
"(",
"\"",
"\"",
",",
"username",
")",
"\n",
"log",
".",
"Debug",
".",
"Println",
"(",
"\"",
"\"",
",",
"publicKey",
")",
"\n\n",
"entity",
":=",
"db",
".",
"NewEntity",
"(",
"username",
",",
"publicKey",
",",
"nil",
")",
"\n\n",
"out",
":=",
"util",
".",
"NewTLV8Container",
"(",
")",
"\n",
"out",
".",
"SetByte",
"(",
"TagSequence",
",",
"0x2",
")",
"\n\n",
"switch",
"method",
"{",
"case",
"PairingMethodDelete",
":",
"log",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"username",
")",
"\n",
"c",
".",
"database",
".",
"DeleteEntity",
"(",
"entity",
")",
"\n",
"case",
"PairingMethodAdd",
":",
"err",
":=",
"c",
".",
"database",
".",
"SaveEntity",
"(",
"entity",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Info",
".",
"Panic",
"(",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"method",
")",
"\n",
"}",
"\n\n",
"return",
"out",
",",
"nil",
"\n",
"}"
]
| // Handle processes a container to pair with a new client without going through the pairing process. | [
"Handle",
"processes",
"a",
"container",
"to",
"pair",
"with",
"a",
"new",
"client",
"without",
"going",
"through",
"the",
"pairing",
"process",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/pairing_controller.go#L26-L57 |
9,228 | brutella/hc | db/database.go | NewTempDatabase | func NewTempDatabase() (Database, error) {
storage, err := util.NewTempFileStorage()
return NewDatabaseWithStorage(storage), err
} | go | func NewTempDatabase() (Database, error) {
storage, err := util.NewTempFileStorage()
return NewDatabaseWithStorage(storage), err
} | [
"func",
"NewTempDatabase",
"(",
")",
"(",
"Database",
",",
"error",
")",
"{",
"storage",
",",
"err",
":=",
"util",
".",
"NewTempFileStorage",
"(",
")",
"\n",
"return",
"NewDatabaseWithStorage",
"(",
"storage",
")",
",",
"err",
"\n",
"}"
]
| // NewTempDatabase returns a temp database | [
"NewTempDatabase",
"returns",
"a",
"temp",
"database"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/db/database.go#L29-L32 |
9,229 | brutella/hc | db/database.go | NewDatabase | func NewDatabase(path string) (Database, error) {
storage, err := util.NewFileStorage(path)
if err != nil {
return nil, err
}
return NewDatabaseWithStorage(storage), nil
} | go | func NewDatabase(path string) (Database, error) {
storage, err := util.NewFileStorage(path)
if err != nil {
return nil, err
}
return NewDatabaseWithStorage(storage), nil
} | [
"func",
"NewDatabase",
"(",
"path",
"string",
")",
"(",
"Database",
",",
"error",
")",
"{",
"storage",
",",
"err",
":=",
"util",
".",
"NewFileStorage",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"NewDatabaseWithStorage",
"(",
"storage",
")",
",",
"nil",
"\n",
"}"
]
| // NewDatabase returns a database which stores data into the folder specified by the argument string. | [
"NewDatabase",
"returns",
"a",
"database",
"which",
"stores",
"data",
"into",
"the",
"folder",
"specified",
"by",
"the",
"argument",
"string",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/db/database.go#L35-L42 |
9,230 | brutella/hc | db/database.go | NewDatabaseWithStorage | func NewDatabaseWithStorage(storage util.Storage) Database {
c := database{storage: storage}
return &c
} | go | func NewDatabaseWithStorage(storage util.Storage) Database {
c := database{storage: storage}
return &c
} | [
"func",
"NewDatabaseWithStorage",
"(",
"storage",
"util",
".",
"Storage",
")",
"Database",
"{",
"c",
":=",
"database",
"{",
"storage",
":",
"storage",
"}",
"\n\n",
"return",
"&",
"c",
"\n",
"}"
]
| // NewDatabaseWithStorage returns a database which uses the argument storage to store data. | [
"NewDatabaseWithStorage",
"returns",
"a",
"database",
"which",
"uses",
"the",
"argument",
"storage",
"to",
"store",
"data",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/db/database.go#L45-L49 |
9,231 | brutella/hc | db/database.go | EntityWithName | func (db *database) EntityWithName(name string) (e Entity, err error) {
return db.entityForKey(toEntityKey(name))
} | go | func (db *database) EntityWithName(name string) (e Entity, err error) {
return db.entityForKey(toEntityKey(name))
} | [
"func",
"(",
"db",
"*",
"database",
")",
"EntityWithName",
"(",
"name",
"string",
")",
"(",
"e",
"Entity",
",",
"err",
"error",
")",
"{",
"return",
"db",
".",
"entityForKey",
"(",
"toEntityKey",
"(",
"name",
")",
")",
"\n",
"}"
]
| // EntityWithName returns a entity for a specific name
// The method tries to load the ltpk from disk and returns initialized client object.
// The method returns nil when no file for this client could be found. | [
"EntityWithName",
"returns",
"a",
"entity",
"for",
"a",
"specific",
"name",
"The",
"method",
"tries",
"to",
"load",
"the",
"ltpk",
"from",
"disk",
"and",
"returns",
"initialized",
"client",
"object",
".",
"The",
"method",
"returns",
"nil",
"when",
"no",
"file",
"for",
"this",
"client",
"could",
"be",
"found",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/db/database.go#L54-L56 |
9,232 | brutella/hc | hap/endpoint/resource.go | NewResource | func NewResource(context hap.Context, imgFn GetImageFunc) *Resource {
r := Resource{
context: context,
imgFn: imgFn,
}
return &r
} | go | func NewResource(context hap.Context, imgFn GetImageFunc) *Resource {
r := Resource{
context: context,
imgFn: imgFn,
}
return &r
} | [
"func",
"NewResource",
"(",
"context",
"hap",
".",
"Context",
",",
"imgFn",
"GetImageFunc",
")",
"*",
"Resource",
"{",
"r",
":=",
"Resource",
"{",
"context",
":",
"context",
",",
"imgFn",
":",
"imgFn",
",",
"}",
"\n\n",
"return",
"&",
"r",
"\n",
"}"
]
| // NewResource returns a new handler for resource requests | [
"NewResource",
"returns",
"a",
"new",
"handler",
"for",
"resource",
"requests"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/endpoint/resource.go#L25-L32 |
9,233 | brutella/hc | db/entity.go | NewRandomEntityWithName | func NewRandomEntityWithName(name string) (e Entity, err error) {
var public []byte
var private []byte
public, private, err = generateKeyPairs()
if err == nil && len(public) > 0 && len(private) > 0 {
e = NewEntity(name, public, private)
}
return
} | go | func NewRandomEntityWithName(name string) (e Entity, err error) {
var public []byte
var private []byte
public, private, err = generateKeyPairs()
if err == nil && len(public) > 0 && len(private) > 0 {
e = NewEntity(name, public, private)
}
return
} | [
"func",
"NewRandomEntityWithName",
"(",
"name",
"string",
")",
"(",
"e",
"Entity",
",",
"err",
"error",
")",
"{",
"var",
"public",
"[",
"]",
"byte",
"\n",
"var",
"private",
"[",
"]",
"byte",
"\n\n",
"public",
",",
"private",
",",
"err",
"=",
"generateKeyPairs",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"len",
"(",
"public",
")",
">",
"0",
"&&",
"len",
"(",
"private",
")",
">",
"0",
"{",
"e",
"=",
"NewEntity",
"(",
"name",
",",
"public",
",",
"private",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // NewRandomEntityWithName returns an entity with a random private and public keys | [
"NewRandomEntityWithName",
"returns",
"an",
"entity",
"with",
"a",
"random",
"private",
"and",
"public",
"keys"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/db/entity.go#L15-L25 |
9,234 | brutella/hc | db/entity.go | NewEntity | func NewEntity(name string, publicKey, privateKey []byte) Entity {
return Entity{Name: name, PublicKey: publicKey, PrivateKey: privateKey}
} | go | func NewEntity(name string, publicKey, privateKey []byte) Entity {
return Entity{Name: name, PublicKey: publicKey, PrivateKey: privateKey}
} | [
"func",
"NewEntity",
"(",
"name",
"string",
",",
"publicKey",
",",
"privateKey",
"[",
"]",
"byte",
")",
"Entity",
"{",
"return",
"Entity",
"{",
"Name",
":",
"name",
",",
"PublicKey",
":",
"publicKey",
",",
"PrivateKey",
":",
"privateKey",
"}",
"\n",
"}"
]
| // NewEntity returns a entity with a name, public and private key. | [
"NewEntity",
"returns",
"a",
"entity",
"with",
"a",
"name",
"public",
"and",
"private",
"key",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/db/entity.go#L28-L30 |
9,235 | brutella/hc | db/entity.go | generateKeyPairs | func generateKeyPairs() ([]byte, []byte, error) {
str := util.RandomHexString()
public, private, err := crypto.ED25519GenerateKey(str)
return public, private, err
} | go | func generateKeyPairs() ([]byte, []byte, error) {
str := util.RandomHexString()
public, private, err := crypto.ED25519GenerateKey(str)
return public, private, err
} | [
"func",
"generateKeyPairs",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"str",
":=",
"util",
".",
"RandomHexString",
"(",
")",
"\n",
"public",
",",
"private",
",",
"err",
":=",
"crypto",
".",
"ED25519GenerateKey",
"(",
"str",
")",
"\n",
"return",
"public",
",",
"private",
",",
"err",
"\n",
"}"
]
| // generateKeyPairs generates random public and private key pairs | [
"generateKeyPairs",
"generates",
"random",
"public",
"and",
"private",
"key",
"pairs"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/db/entity.go#L33-L37 |
9,236 | brutella/hc | hap/pair/verify_session.go | NewVerifySession | func NewVerifySession() *VerifySession {
privateKey := curve25519.GeneratePrivateKey()
publicKey := curve25519.PublicKey(privateKey)
return &VerifySession{
PublicKey: publicKey,
PrivateKey: privateKey,
}
} | go | func NewVerifySession() *VerifySession {
privateKey := curve25519.GeneratePrivateKey()
publicKey := curve25519.PublicKey(privateKey)
return &VerifySession{
PublicKey: publicKey,
PrivateKey: privateKey,
}
} | [
"func",
"NewVerifySession",
"(",
")",
"*",
"VerifySession",
"{",
"privateKey",
":=",
"curve25519",
".",
"GeneratePrivateKey",
"(",
")",
"\n",
"publicKey",
":=",
"curve25519",
".",
"PublicKey",
"(",
"privateKey",
")",
"\n\n",
"return",
"&",
"VerifySession",
"{",
"PublicKey",
":",
"publicKey",
",",
"PrivateKey",
":",
"privateKey",
",",
"}",
"\n",
"}"
]
| // NewVerifySession creates a new session with random public and private key | [
"NewVerifySession",
"creates",
"a",
"new",
"session",
"with",
"random",
"public",
"and",
"private",
"key"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/verify_session.go#L18-L26 |
9,237 | brutella/hc | hap/pair/verify_session.go | GenerateSharedKeyWithOtherPublicKey | func (s *VerifySession) GenerateSharedKeyWithOtherPublicKey(otherPublicKey [32]byte) {
sharedKey := curve25519.SharedSecret(s.PrivateKey, otherPublicKey)
s.OtherPublicKey = otherPublicKey
s.SharedKey = sharedKey
} | go | func (s *VerifySession) GenerateSharedKeyWithOtherPublicKey(otherPublicKey [32]byte) {
sharedKey := curve25519.SharedSecret(s.PrivateKey, otherPublicKey)
s.OtherPublicKey = otherPublicKey
s.SharedKey = sharedKey
} | [
"func",
"(",
"s",
"*",
"VerifySession",
")",
"GenerateSharedKeyWithOtherPublicKey",
"(",
"otherPublicKey",
"[",
"32",
"]",
"byte",
")",
"{",
"sharedKey",
":=",
"curve25519",
".",
"SharedSecret",
"(",
"s",
".",
"PrivateKey",
",",
"otherPublicKey",
")",
"\n\n",
"s",
".",
"OtherPublicKey",
"=",
"otherPublicKey",
"\n",
"s",
".",
"SharedKey",
"=",
"sharedKey",
"\n",
"}"
]
| // GenerateSharedKeyWithOtherPublicKey generates a Curve25519 shared key based on a public key.
// The other public key is also stored for further use in `otherPublicKey` property. | [
"GenerateSharedKeyWithOtherPublicKey",
"generates",
"a",
"Curve25519",
"shared",
"key",
"based",
"on",
"a",
"public",
"key",
".",
"The",
"other",
"public",
"key",
"is",
"also",
"stored",
"for",
"further",
"use",
"in",
"otherPublicKey",
"property",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/verify_session.go#L30-L35 |
9,238 | brutella/hc | hap/pair/verify_session.go | SetupEncryptionKey | func (s *VerifySession) SetupEncryptionKey(salt []byte, info []byte) error {
hash, err := hkdf.Sha512(s.SharedKey[:], salt, info)
if err == nil {
s.EncryptionKey = hash
}
return err
} | go | func (s *VerifySession) SetupEncryptionKey(salt []byte, info []byte) error {
hash, err := hkdf.Sha512(s.SharedKey[:], salt, info)
if err == nil {
s.EncryptionKey = hash
}
return err
} | [
"func",
"(",
"s",
"*",
"VerifySession",
")",
"SetupEncryptionKey",
"(",
"salt",
"[",
"]",
"byte",
",",
"info",
"[",
"]",
"byte",
")",
"error",
"{",
"hash",
",",
"err",
":=",
"hkdf",
".",
"Sha512",
"(",
"s",
".",
"SharedKey",
"[",
":",
"]",
",",
"salt",
",",
"info",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"s",
".",
"EncryptionKey",
"=",
"hash",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // SetupEncryptionKey generates an encryption key based on the shared key, salt and info. | [
"SetupEncryptionKey",
"generates",
"an",
"encryption",
"key",
"based",
"on",
"the",
"shared",
"key",
"salt",
"and",
"info",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/verify_session.go#L38-L45 |
9,239 | brutella/hc | accessory/television.go | NewTelevision | func NewTelevision(info Info) *Television {
acc := Television{}
acc.Accessory = New(info, TypeTelevision)
acc.Television = service.NewTelevision()
acc.Speaker = service.NewSpeaker()
acc.AddService(acc.Television.Service)
acc.AddService(acc.Speaker.Service)
return &acc
} | go | func NewTelevision(info Info) *Television {
acc := Television{}
acc.Accessory = New(info, TypeTelevision)
acc.Television = service.NewTelevision()
acc.Speaker = service.NewSpeaker()
acc.AddService(acc.Television.Service)
acc.AddService(acc.Speaker.Service)
return &acc
} | [
"func",
"NewTelevision",
"(",
"info",
"Info",
")",
"*",
"Television",
"{",
"acc",
":=",
"Television",
"{",
"}",
"\n",
"acc",
".",
"Accessory",
"=",
"New",
"(",
"info",
",",
"TypeTelevision",
")",
"\n",
"acc",
".",
"Television",
"=",
"service",
".",
"NewTelevision",
"(",
")",
"\n",
"acc",
".",
"Speaker",
"=",
"service",
".",
"NewSpeaker",
"(",
")",
"\n\n",
"acc",
".",
"AddService",
"(",
"acc",
".",
"Television",
".",
"Service",
")",
"\n",
"acc",
".",
"AddService",
"(",
"acc",
".",
"Speaker",
".",
"Service",
")",
"\n\n",
"return",
"&",
"acc",
"\n",
"}"
]
| // NewTelevision returns a television accessory. | [
"NewTelevision",
"returns",
"a",
"television",
"accessory",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/television.go#L14-L24 |
9,240 | brutella/hc | hap/pair/verify_server_controller.go | NewVerifyServerController | func NewVerifyServerController(database db.Database, context hap.Context) *VerifyServerController {
controller := VerifyServerController{
database: database,
context: context,
session: NewVerifySession(),
step: VerifyStepWaiting,
}
return &controller
} | go | func NewVerifyServerController(database db.Database, context hap.Context) *VerifyServerController {
controller := VerifyServerController{
database: database,
context: context,
session: NewVerifySession(),
step: VerifyStepWaiting,
}
return &controller
} | [
"func",
"NewVerifyServerController",
"(",
"database",
"db",
".",
"Database",
",",
"context",
"hap",
".",
"Context",
")",
"*",
"VerifyServerController",
"{",
"controller",
":=",
"VerifyServerController",
"{",
"database",
":",
"database",
",",
"context",
":",
"context",
",",
"session",
":",
"NewVerifySession",
"(",
")",
",",
"step",
":",
"VerifyStepWaiting",
",",
"}",
"\n\n",
"return",
"&",
"controller",
"\n",
"}"
]
| // NewVerifyServerController returns a new verify server controller. | [
"NewVerifyServerController",
"returns",
"a",
"new",
"verify",
"server",
"controller",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/verify_server_controller.go#L28-L37 |
9,241 | brutella/hc | hap/pair/verify_server_controller.go | Handle | func (verify *VerifyServerController) Handle(in util.Container) (util.Container, error) {
var out util.Container
var err error
method := PairMethodType(in.GetByte(TagPairingMethod))
// It is valid that method is not sent
// If method is sent then it must be 0x00
if method != PairingMethodDefault {
return nil, errInvalidPairMethod(method)
}
seq := VerifyStepType(in.GetByte(TagSequence))
switch seq {
case VerifyStepStartRequest:
if verify.step != VerifyStepWaiting {
verify.reset()
return nil, errInvalidInternalVerifyStep(verify.step)
}
out, err = verify.handlePairVerifyStart(in)
case VerifyStepFinishRequest:
if verify.step != VerifyStepStartResponse {
verify.reset()
return nil, errInvalidInternalVerifyStep(verify.step)
}
out, err = verify.handlePairVerifyFinish(in)
default:
return nil, errInvalidVerifyStep(seq)
}
return out, err
} | go | func (verify *VerifyServerController) Handle(in util.Container) (util.Container, error) {
var out util.Container
var err error
method := PairMethodType(in.GetByte(TagPairingMethod))
// It is valid that method is not sent
// If method is sent then it must be 0x00
if method != PairingMethodDefault {
return nil, errInvalidPairMethod(method)
}
seq := VerifyStepType(in.GetByte(TagSequence))
switch seq {
case VerifyStepStartRequest:
if verify.step != VerifyStepWaiting {
verify.reset()
return nil, errInvalidInternalVerifyStep(verify.step)
}
out, err = verify.handlePairVerifyStart(in)
case VerifyStepFinishRequest:
if verify.step != VerifyStepStartResponse {
verify.reset()
return nil, errInvalidInternalVerifyStep(verify.step)
}
out, err = verify.handlePairVerifyFinish(in)
default:
return nil, errInvalidVerifyStep(seq)
}
return out, err
} | [
"func",
"(",
"verify",
"*",
"VerifyServerController",
")",
"Handle",
"(",
"in",
"util",
".",
"Container",
")",
"(",
"util",
".",
"Container",
",",
"error",
")",
"{",
"var",
"out",
"util",
".",
"Container",
"\n",
"var",
"err",
"error",
"\n\n",
"method",
":=",
"PairMethodType",
"(",
"in",
".",
"GetByte",
"(",
"TagPairingMethod",
")",
")",
"\n\n",
"// It is valid that method is not sent",
"// If method is sent then it must be 0x00",
"if",
"method",
"!=",
"PairingMethodDefault",
"{",
"return",
"nil",
",",
"errInvalidPairMethod",
"(",
"method",
")",
"\n",
"}",
"\n\n",
"seq",
":=",
"VerifyStepType",
"(",
"in",
".",
"GetByte",
"(",
"TagSequence",
")",
")",
"\n\n",
"switch",
"seq",
"{",
"case",
"VerifyStepStartRequest",
":",
"if",
"verify",
".",
"step",
"!=",
"VerifyStepWaiting",
"{",
"verify",
".",
"reset",
"(",
")",
"\n",
"return",
"nil",
",",
"errInvalidInternalVerifyStep",
"(",
"verify",
".",
"step",
")",
"\n",
"}",
"\n",
"out",
",",
"err",
"=",
"verify",
".",
"handlePairVerifyStart",
"(",
"in",
")",
"\n",
"case",
"VerifyStepFinishRequest",
":",
"if",
"verify",
".",
"step",
"!=",
"VerifyStepStartResponse",
"{",
"verify",
".",
"reset",
"(",
")",
"\n",
"return",
"nil",
",",
"errInvalidInternalVerifyStep",
"(",
"verify",
".",
"step",
")",
"\n",
"}",
"\n\n",
"out",
",",
"err",
"=",
"verify",
".",
"handlePairVerifyFinish",
"(",
"in",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"errInvalidVerifyStep",
"(",
"seq",
")",
"\n",
"}",
"\n\n",
"return",
"out",
",",
"err",
"\n",
"}"
]
| // Handle processes a container to verify if a client is paired correctly. | [
"Handle",
"processes",
"a",
"container",
"to",
"verify",
"if",
"a",
"client",
"is",
"paired",
"correctly",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/verify_server_controller.go#L45-L78 |
9,242 | brutella/hc | hap/endpoint/pair-setup.go | NewPairSetup | func NewPairSetup(context hap.Context, device hap.SecuredDevice, database db.Database, emitter event.Emitter) *PairSetup {
endpoint := PairSetup{
device: device,
database: database,
context: context,
emitter: emitter,
}
return &endpoint
} | go | func NewPairSetup(context hap.Context, device hap.SecuredDevice, database db.Database, emitter event.Emitter) *PairSetup {
endpoint := PairSetup{
device: device,
database: database,
context: context,
emitter: emitter,
}
return &endpoint
} | [
"func",
"NewPairSetup",
"(",
"context",
"hap",
".",
"Context",
",",
"device",
"hap",
".",
"SecuredDevice",
",",
"database",
"db",
".",
"Database",
",",
"emitter",
"event",
".",
"Emitter",
")",
"*",
"PairSetup",
"{",
"endpoint",
":=",
"PairSetup",
"{",
"device",
":",
"device",
",",
"database",
":",
"database",
",",
"context",
":",
"context",
",",
"emitter",
":",
"emitter",
",",
"}",
"\n\n",
"return",
"&",
"endpoint",
"\n",
"}"
]
| // NewPairSetup returns a new handler for pairing endpoint | [
"NewPairSetup",
"returns",
"a",
"new",
"handler",
"for",
"pairing",
"endpoint"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/endpoint/pair-setup.go#L32-L41 |
9,243 | brutella/hc | hap/controller/characteristic_controller.go | HandleUpdateCharacteristics | func (ctr *CharacteristicController) HandleUpdateCharacteristics(r io.Reader, conn net.Conn) error {
b, err := ioutil.ReadAll(r)
if err != nil {
return err
}
var chars data.Characteristics
err = json.Unmarshal(b, &chars)
if err != nil {
return err
}
log.Debug.Println(string(b))
for _, c := range chars.Characteristics {
characteristic := ctr.GetCharacteristic(c.AccessoryID, c.CharacteristicID)
if characteristic == nil {
log.Info.Printf("Could not find characteristic with aid %d and iid %d\n", c.AccessoryID, c.CharacteristicID)
continue
}
if c.Value != nil {
characteristic.UpdateValueFromConnection(c.Value, conn)
}
if events, ok := c.Events.(bool); ok == true {
characteristic.SetEventsEnabled(events)
}
}
return err
} | go | func (ctr *CharacteristicController) HandleUpdateCharacteristics(r io.Reader, conn net.Conn) error {
b, err := ioutil.ReadAll(r)
if err != nil {
return err
}
var chars data.Characteristics
err = json.Unmarshal(b, &chars)
if err != nil {
return err
}
log.Debug.Println(string(b))
for _, c := range chars.Characteristics {
characteristic := ctr.GetCharacteristic(c.AccessoryID, c.CharacteristicID)
if characteristic == nil {
log.Info.Printf("Could not find characteristic with aid %d and iid %d\n", c.AccessoryID, c.CharacteristicID)
continue
}
if c.Value != nil {
characteristic.UpdateValueFromConnection(c.Value, conn)
}
if events, ok := c.Events.(bool); ok == true {
characteristic.SetEventsEnabled(events)
}
}
return err
} | [
"func",
"(",
"ctr",
"*",
"CharacteristicController",
")",
"HandleUpdateCharacteristics",
"(",
"r",
"io",
".",
"Reader",
",",
"conn",
"net",
".",
"Conn",
")",
"error",
"{",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"chars",
"data",
".",
"Characteristics",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"chars",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"log",
".",
"Debug",
".",
"Println",
"(",
"string",
"(",
"b",
")",
")",
"\n\n",
"for",
"_",
",",
"c",
":=",
"range",
"chars",
".",
"Characteristics",
"{",
"characteristic",
":=",
"ctr",
".",
"GetCharacteristic",
"(",
"c",
".",
"AccessoryID",
",",
"c",
".",
"CharacteristicID",
")",
"\n",
"if",
"characteristic",
"==",
"nil",
"{",
"log",
".",
"Info",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"c",
".",
"AccessoryID",
",",
"c",
".",
"CharacteristicID",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"Value",
"!=",
"nil",
"{",
"characteristic",
".",
"UpdateValueFromConnection",
"(",
"c",
".",
"Value",
",",
"conn",
")",
"\n",
"}",
"\n\n",
"if",
"events",
",",
"ok",
":=",
"c",
".",
"Events",
".",
"(",
"bool",
")",
";",
"ok",
"==",
"true",
"{",
"characteristic",
".",
"SetEventsEnabled",
"(",
"events",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // HandleUpdateCharacteristics handles an update characteristic request. The bytes must represent
// a data.Characteristics json. | [
"HandleUpdateCharacteristics",
"handles",
"an",
"update",
"characteristic",
"request",
".",
"The",
"bytes",
"must",
"represent",
"a",
"data",
".",
"Characteristics",
"json",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/controller/characteristic_controller.go#L64-L95 |
9,244 | brutella/hc | hap/controller/characteristic_controller.go | GetCharacteristic | func (ctr *CharacteristicController) GetCharacteristic(aid int64, iid int64) *characteristic.Characteristic {
for _, a := range ctr.container.Accessories {
if a.GetID() == aid {
for _, s := range a.GetServices() {
for _, c := range s.GetCharacteristics() {
if c.GetID() == iid {
return c
}
}
}
}
}
return nil
} | go | func (ctr *CharacteristicController) GetCharacteristic(aid int64, iid int64) *characteristic.Characteristic {
for _, a := range ctr.container.Accessories {
if a.GetID() == aid {
for _, s := range a.GetServices() {
for _, c := range s.GetCharacteristics() {
if c.GetID() == iid {
return c
}
}
}
}
}
return nil
} | [
"func",
"(",
"ctr",
"*",
"CharacteristicController",
")",
"GetCharacteristic",
"(",
"aid",
"int64",
",",
"iid",
"int64",
")",
"*",
"characteristic",
".",
"Characteristic",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"ctr",
".",
"container",
".",
"Accessories",
"{",
"if",
"a",
".",
"GetID",
"(",
")",
"==",
"aid",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"a",
".",
"GetServices",
"(",
")",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"s",
".",
"GetCharacteristics",
"(",
")",
"{",
"if",
"c",
".",
"GetID",
"(",
")",
"==",
"iid",
"{",
"return",
"c",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // GetCharacteristic returns the characteristic identified by the accessory id aid and characteristic id iid | [
"GetCharacteristic",
"returns",
"the",
"characteristic",
"identified",
"by",
"the",
"accessory",
"id",
"aid",
"and",
"characteristic",
"id",
"iid"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/controller/characteristic_controller.go#L98-L111 |
9,245 | brutella/hc | accessory/thermostat.go | NewThermostat | func NewThermostat(info Info, temp, min, max, steps float64) *Thermostat {
acc := Thermostat{}
acc.Accessory = New(info, TypeThermostat)
acc.Thermostat = service.NewThermostat()
acc.Thermostat.CurrentTemperature.SetValue(temp)
acc.Thermostat.CurrentTemperature.SetMinValue(min)
acc.Thermostat.CurrentTemperature.SetMaxValue(max)
acc.Thermostat.CurrentTemperature.SetStepValue(steps)
acc.Thermostat.TargetTemperature.SetValue(temp)
acc.Thermostat.TargetTemperature.SetMinValue(min)
acc.Thermostat.TargetTemperature.SetMaxValue(max)
acc.Thermostat.TargetTemperature.SetStepValue(steps)
acc.AddService(acc.Thermostat.Service)
return &acc
} | go | func NewThermostat(info Info, temp, min, max, steps float64) *Thermostat {
acc := Thermostat{}
acc.Accessory = New(info, TypeThermostat)
acc.Thermostat = service.NewThermostat()
acc.Thermostat.CurrentTemperature.SetValue(temp)
acc.Thermostat.CurrentTemperature.SetMinValue(min)
acc.Thermostat.CurrentTemperature.SetMaxValue(max)
acc.Thermostat.CurrentTemperature.SetStepValue(steps)
acc.Thermostat.TargetTemperature.SetValue(temp)
acc.Thermostat.TargetTemperature.SetMinValue(min)
acc.Thermostat.TargetTemperature.SetMaxValue(max)
acc.Thermostat.TargetTemperature.SetStepValue(steps)
acc.AddService(acc.Thermostat.Service)
return &acc
} | [
"func",
"NewThermostat",
"(",
"info",
"Info",
",",
"temp",
",",
"min",
",",
"max",
",",
"steps",
"float64",
")",
"*",
"Thermostat",
"{",
"acc",
":=",
"Thermostat",
"{",
"}",
"\n",
"acc",
".",
"Accessory",
"=",
"New",
"(",
"info",
",",
"TypeThermostat",
")",
"\n",
"acc",
".",
"Thermostat",
"=",
"service",
".",
"NewThermostat",
"(",
")",
"\n",
"acc",
".",
"Thermostat",
".",
"CurrentTemperature",
".",
"SetValue",
"(",
"temp",
")",
"\n",
"acc",
".",
"Thermostat",
".",
"CurrentTemperature",
".",
"SetMinValue",
"(",
"min",
")",
"\n",
"acc",
".",
"Thermostat",
".",
"CurrentTemperature",
".",
"SetMaxValue",
"(",
"max",
")",
"\n",
"acc",
".",
"Thermostat",
".",
"CurrentTemperature",
".",
"SetStepValue",
"(",
"steps",
")",
"\n\n",
"acc",
".",
"Thermostat",
".",
"TargetTemperature",
".",
"SetValue",
"(",
"temp",
")",
"\n",
"acc",
".",
"Thermostat",
".",
"TargetTemperature",
".",
"SetMinValue",
"(",
"min",
")",
"\n",
"acc",
".",
"Thermostat",
".",
"TargetTemperature",
".",
"SetMaxValue",
"(",
"max",
")",
"\n",
"acc",
".",
"Thermostat",
".",
"TargetTemperature",
".",
"SetStepValue",
"(",
"steps",
")",
"\n\n",
"acc",
".",
"AddService",
"(",
"acc",
".",
"Thermostat",
".",
"Service",
")",
"\n\n",
"return",
"&",
"acc",
"\n",
"}"
]
| // NewThermostat returns a Thermostat which implements model.Thermostat. | [
"NewThermostat",
"returns",
"a",
"Thermostat",
"which",
"implements",
"model",
".",
"Thermostat",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/thermostat.go#L14-L31 |
9,246 | brutella/hc | hap/http/server.go | NewServer | func NewServer(c Config) *Server {
// os gives us a free Port when Port is ""
ln, err := net.Listen("tcp", c.Port)
if err != nil {
log.Info.Panic(err)
}
_, port, _ := net.SplitHostPort(ln.Addr().String())
s := Server{
context: c.Context,
database: c.Database,
container: c.Container,
device: c.Device,
Mux: http.NewServeMux(),
mutex: c.Mutex,
listener: ln.(*net.TCPListener),
port: port,
emitter: c.Emitter,
}
s.setupEndpoints()
return &s
} | go | func NewServer(c Config) *Server {
// os gives us a free Port when Port is ""
ln, err := net.Listen("tcp", c.Port)
if err != nil {
log.Info.Panic(err)
}
_, port, _ := net.SplitHostPort(ln.Addr().String())
s := Server{
context: c.Context,
database: c.Database,
container: c.Container,
device: c.Device,
Mux: http.NewServeMux(),
mutex: c.Mutex,
listener: ln.(*net.TCPListener),
port: port,
emitter: c.Emitter,
}
s.setupEndpoints()
return &s
} | [
"func",
"NewServer",
"(",
"c",
"Config",
")",
"*",
"Server",
"{",
"// os gives us a free Port when Port is \"\"",
"ln",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"c",
".",
"Port",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Info",
".",
"Panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"_",
",",
"port",
",",
"_",
":=",
"net",
".",
"SplitHostPort",
"(",
"ln",
".",
"Addr",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"s",
":=",
"Server",
"{",
"context",
":",
"c",
".",
"Context",
",",
"database",
":",
"c",
".",
"Database",
",",
"container",
":",
"c",
".",
"Container",
",",
"device",
":",
"c",
".",
"Device",
",",
"Mux",
":",
"http",
".",
"NewServeMux",
"(",
")",
",",
"mutex",
":",
"c",
".",
"Mutex",
",",
"listener",
":",
"ln",
".",
"(",
"*",
"net",
".",
"TCPListener",
")",
",",
"port",
":",
"port",
",",
"emitter",
":",
"c",
".",
"Emitter",
",",
"}",
"\n\n",
"s",
".",
"setupEndpoints",
"(",
")",
"\n\n",
"return",
"&",
"s",
"\n",
"}"
]
| // NewServer returns a server | [
"NewServer",
"returns",
"a",
"server"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/http/server.go#L46-L71 |
9,247 | brutella/hc | hap/http/server.go | listenAndServe | func (s *Server) listenAndServe(addr string, handler http.Handler, context hap.Context) error {
server := http.Server{Addr: addr, Handler: handler}
// Use a TCPListener
listener := hap.NewTCPListener(s.listener, context)
s.hapListener = listener
return server.Serve(listener)
} | go | func (s *Server) listenAndServe(addr string, handler http.Handler, context hap.Context) error {
server := http.Server{Addr: addr, Handler: handler}
// Use a TCPListener
listener := hap.NewTCPListener(s.listener, context)
s.hapListener = listener
return server.Serve(listener)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"listenAndServe",
"(",
"addr",
"string",
",",
"handler",
"http",
".",
"Handler",
",",
"context",
"hap",
".",
"Context",
")",
"error",
"{",
"server",
":=",
"http",
".",
"Server",
"{",
"Addr",
":",
"addr",
",",
"Handler",
":",
"handler",
"}",
"\n",
"// Use a TCPListener",
"listener",
":=",
"hap",
".",
"NewTCPListener",
"(",
"s",
".",
"listener",
",",
"context",
")",
"\n",
"s",
".",
"hapListener",
"=",
"listener",
"\n",
"return",
"server",
".",
"Serve",
"(",
"listener",
")",
"\n",
"}"
]
| // listenAndServe returns a http.Server to listen on a specific address | [
"listenAndServe",
"returns",
"a",
"http",
".",
"Server",
"to",
"listen",
"on",
"a",
"specific",
"address"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/http/server.go#L90-L96 |
9,248 | brutella/hc | hap/http/server.go | setupEndpoints | func (s *Server) setupEndpoints() {
containerController := controller.NewContainerController(s.container)
characteristicsController := controller.NewCharacteristicController(s.container)
pairingController := pair.NewPairingController(s.database)
s.Mux.Handle("/pair-setup", endpoint.NewPairSetup(s.context, s.device, s.database, s.emitter))
s.Mux.Handle("/pair-verify", endpoint.NewPairVerify(s.context, s.database))
s.Mux.Handle("/accessories", endpoint.NewAccessories(containerController, s.mutex))
s.Mux.Handle("/characteristics", endpoint.NewCharacteristics(s.context, characteristicsController, s.mutex))
s.Mux.Handle("/pairings", endpoint.NewPairing(pairingController, s.emitter))
s.Mux.Handle("/identify", endpoint.NewIdentify(containerController))
} | go | func (s *Server) setupEndpoints() {
containerController := controller.NewContainerController(s.container)
characteristicsController := controller.NewCharacteristicController(s.container)
pairingController := pair.NewPairingController(s.database)
s.Mux.Handle("/pair-setup", endpoint.NewPairSetup(s.context, s.device, s.database, s.emitter))
s.Mux.Handle("/pair-verify", endpoint.NewPairVerify(s.context, s.database))
s.Mux.Handle("/accessories", endpoint.NewAccessories(containerController, s.mutex))
s.Mux.Handle("/characteristics", endpoint.NewCharacteristics(s.context, characteristicsController, s.mutex))
s.Mux.Handle("/pairings", endpoint.NewPairing(pairingController, s.emitter))
s.Mux.Handle("/identify", endpoint.NewIdentify(containerController))
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"setupEndpoints",
"(",
")",
"{",
"containerController",
":=",
"controller",
".",
"NewContainerController",
"(",
"s",
".",
"container",
")",
"\n",
"characteristicsController",
":=",
"controller",
".",
"NewCharacteristicController",
"(",
"s",
".",
"container",
")",
"\n",
"pairingController",
":=",
"pair",
".",
"NewPairingController",
"(",
"s",
".",
"database",
")",
"\n\n",
"s",
".",
"Mux",
".",
"Handle",
"(",
"\"",
"\"",
",",
"endpoint",
".",
"NewPairSetup",
"(",
"s",
".",
"context",
",",
"s",
".",
"device",
",",
"s",
".",
"database",
",",
"s",
".",
"emitter",
")",
")",
"\n",
"s",
".",
"Mux",
".",
"Handle",
"(",
"\"",
"\"",
",",
"endpoint",
".",
"NewPairVerify",
"(",
"s",
".",
"context",
",",
"s",
".",
"database",
")",
")",
"\n",
"s",
".",
"Mux",
".",
"Handle",
"(",
"\"",
"\"",
",",
"endpoint",
".",
"NewAccessories",
"(",
"containerController",
",",
"s",
".",
"mutex",
")",
")",
"\n",
"s",
".",
"Mux",
".",
"Handle",
"(",
"\"",
"\"",
",",
"endpoint",
".",
"NewCharacteristics",
"(",
"s",
".",
"context",
",",
"characteristicsController",
",",
"s",
".",
"mutex",
")",
")",
"\n",
"s",
".",
"Mux",
".",
"Handle",
"(",
"\"",
"\"",
",",
"endpoint",
".",
"NewPairing",
"(",
"pairingController",
",",
"s",
".",
"emitter",
")",
")",
"\n",
"s",
".",
"Mux",
".",
"Handle",
"(",
"\"",
"\"",
",",
"endpoint",
".",
"NewIdentify",
"(",
"containerController",
")",
")",
"\n",
"}"
]
| // setupEndpoints creates controller objects to handle HAP endpoints | [
"setupEndpoints",
"creates",
"controller",
"objects",
"to",
"handle",
"HAP",
"endpoints"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/http/server.go#L103-L114 |
9,249 | brutella/hc | crypto/ed25519.go | ValidateED25519Signature | func ValidateED25519Signature(key, data, signature []byte) bool {
if len(key) != ed25519.PublicKeySize || len(signature) != ed25519.SignatureSize {
return false
}
var k [ed25519.PublicKeySize]byte
var s [ed25519.SignatureSize]byte
copy(k[:], key)
copy(s[:], signature)
return ed25519.Verify(&k, data, &s)
} | go | func ValidateED25519Signature(key, data, signature []byte) bool {
if len(key) != ed25519.PublicKeySize || len(signature) != ed25519.SignatureSize {
return false
}
var k [ed25519.PublicKeySize]byte
var s [ed25519.SignatureSize]byte
copy(k[:], key)
copy(s[:], signature)
return ed25519.Verify(&k, data, &s)
} | [
"func",
"ValidateED25519Signature",
"(",
"key",
",",
"data",
",",
"signature",
"[",
"]",
"byte",
")",
"bool",
"{",
"if",
"len",
"(",
"key",
")",
"!=",
"ed25519",
".",
"PublicKeySize",
"||",
"len",
"(",
"signature",
")",
"!=",
"ed25519",
".",
"SignatureSize",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"var",
"k",
"[",
"ed25519",
".",
"PublicKeySize",
"]",
"byte",
"\n",
"var",
"s",
"[",
"ed25519",
".",
"SignatureSize",
"]",
"byte",
"\n",
"copy",
"(",
"k",
"[",
":",
"]",
",",
"key",
")",
"\n",
"copy",
"(",
"s",
"[",
":",
"]",
",",
"signature",
")",
"\n\n",
"return",
"ed25519",
".",
"Verify",
"(",
"&",
"k",
",",
"data",
",",
"&",
"s",
")",
"\n",
"}"
]
| // ValidateED25519Signature return true when the ED25519 signature is a valid signature of the data based on the key, otherwise false. | [
"ValidateED25519Signature",
"return",
"true",
"when",
"the",
"ED25519",
"signature",
"is",
"a",
"valid",
"signature",
"of",
"the",
"data",
"based",
"on",
"the",
"key",
"otherwise",
"false",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/crypto/ed25519.go#L11-L22 |
9,250 | brutella/hc | crypto/ed25519.go | ED25519Signature | func ED25519Signature(key, data []byte) ([]byte, error) {
if len(key) != ed25519.PrivateKeySize {
return nil, fmt.Errorf("Invalid size of key (%v)", len(key))
}
var k [ed25519.PrivateKeySize]byte
copy(k[:], key)
signature := ed25519.Sign(&k, data)
return signature[:], nil
} | go | func ED25519Signature(key, data []byte) ([]byte, error) {
if len(key) != ed25519.PrivateKeySize {
return nil, fmt.Errorf("Invalid size of key (%v)", len(key))
}
var k [ed25519.PrivateKeySize]byte
copy(k[:], key)
signature := ed25519.Sign(&k, data)
return signature[:], nil
} | [
"func",
"ED25519Signature",
"(",
"key",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"key",
")",
"!=",
"ed25519",
".",
"PrivateKeySize",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"key",
")",
")",
"\n",
"}",
"\n\n",
"var",
"k",
"[",
"ed25519",
".",
"PrivateKeySize",
"]",
"byte",
"\n",
"copy",
"(",
"k",
"[",
":",
"]",
",",
"key",
")",
"\n",
"signature",
":=",
"ed25519",
".",
"Sign",
"(",
"&",
"k",
",",
"data",
")",
"\n\n",
"return",
"signature",
"[",
":",
"]",
",",
"nil",
"\n",
"}"
]
| // ED25519Signature returns the ED25519 signature of data using the key. | [
"ED25519Signature",
"returns",
"the",
"ED25519",
"signature",
"of",
"data",
"using",
"the",
"key",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/crypto/ed25519.go#L25-L35 |
9,251 | brutella/hc | crypto/ed25519.go | ED25519GenerateKey | func ED25519GenerateKey(str string) ([]byte /* public */, []byte /* private */, error) {
b := bytes.NewBuffer([]byte(str))
if len(str) < 32 {
zeros := make([]byte, 32-len(str))
b.Write(zeros)
}
public, private, err := ed25519.GenerateKey(bytes.NewReader(b.Bytes()))
return public[:], private[:], err
} | go | func ED25519GenerateKey(str string) ([]byte /* public */, []byte /* private */, error) {
b := bytes.NewBuffer([]byte(str))
if len(str) < 32 {
zeros := make([]byte, 32-len(str))
b.Write(zeros)
}
public, private, err := ed25519.GenerateKey(bytes.NewReader(b.Bytes()))
return public[:], private[:], err
} | [
"func",
"ED25519GenerateKey",
"(",
"str",
"string",
")",
"(",
"[",
"]",
"byte",
"/* public */",
",",
"[",
"]",
"byte",
"/* private */",
",",
"error",
")",
"{",
"b",
":=",
"bytes",
".",
"NewBuffer",
"(",
"[",
"]",
"byte",
"(",
"str",
")",
")",
"\n",
"if",
"len",
"(",
"str",
")",
"<",
"32",
"{",
"zeros",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"32",
"-",
"len",
"(",
"str",
")",
")",
"\n",
"b",
".",
"Write",
"(",
"zeros",
")",
"\n",
"}",
"\n\n",
"public",
",",
"private",
",",
"err",
":=",
"ed25519",
".",
"GenerateKey",
"(",
"bytes",
".",
"NewReader",
"(",
"b",
".",
"Bytes",
"(",
")",
")",
")",
"\n\n",
"return",
"public",
"[",
":",
"]",
",",
"private",
"[",
":",
"]",
",",
"err",
"\n",
"}"
]
| // ED25519GenerateKey return a public and private ED25519 key pair from a string. | [
"ED25519GenerateKey",
"return",
"a",
"public",
"and",
"private",
"ED25519",
"key",
"pair",
"from",
"a",
"string",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/crypto/ed25519.go#L38-L48 |
9,252 | brutella/hc | gen/golang/path.go | CharacteristicLocalFilePath | func CharacteristicLocalFilePath(char *gen.CharacteristicMetadata) string {
return filepath.Join(CharacteristicLocalDir, CharacteristicFileName(char))
} | go | func CharacteristicLocalFilePath(char *gen.CharacteristicMetadata) string {
return filepath.Join(CharacteristicLocalDir, CharacteristicFileName(char))
} | [
"func",
"CharacteristicLocalFilePath",
"(",
"char",
"*",
"gen",
".",
"CharacteristicMetadata",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"CharacteristicLocalDir",
",",
"CharacteristicFileName",
"(",
"char",
")",
")",
"\n",
"}"
]
| // CharacteristicLocalFilePath returns the filepath to a characteristic | [
"CharacteristicLocalFilePath",
"returns",
"the",
"filepath",
"to",
"a",
"characteristic"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/gen/golang/path.go#L18-L20 |
9,253 | brutella/hc | gen/golang/path.go | CharacteristicRelativeFilePath | func CharacteristicRelativeFilePath(char *gen.CharacteristicMetadata) string {
return filepath.Join(CharacteristicDir, CharacteristicFileName(char))
} | go | func CharacteristicRelativeFilePath(char *gen.CharacteristicMetadata) string {
return filepath.Join(CharacteristicDir, CharacteristicFileName(char))
} | [
"func",
"CharacteristicRelativeFilePath",
"(",
"char",
"*",
"gen",
".",
"CharacteristicMetadata",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"CharacteristicDir",
",",
"CharacteristicFileName",
"(",
"char",
")",
")",
"\n",
"}"
]
| // CharacteristicRelativeFilePath returns the relative filepath to a characteristic | [
"CharacteristicRelativeFilePath",
"returns",
"the",
"relative",
"filepath",
"to",
"a",
"characteristic"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/gen/golang/path.go#L23-L25 |
9,254 | brutella/hc | gen/golang/path.go | ServiceLocalFilePath | func ServiceLocalFilePath(sv *gen.ServiceMetadata) string {
return filepath.Join(ServiceLocalDir, ServiceFileName(sv))
} | go | func ServiceLocalFilePath(sv *gen.ServiceMetadata) string {
return filepath.Join(ServiceLocalDir, ServiceFileName(sv))
} | [
"func",
"ServiceLocalFilePath",
"(",
"sv",
"*",
"gen",
".",
"ServiceMetadata",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"ServiceLocalDir",
",",
"ServiceFileName",
"(",
"sv",
")",
")",
"\n",
"}"
]
| // ServiceLocalFilePath returns the filepath to a service | [
"ServiceLocalFilePath",
"returns",
"the",
"filepath",
"to",
"a",
"service"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/gen/golang/path.go#L28-L30 |
9,255 | brutella/hc | gen/golang/path.go | ServiceRelativeFilePath | func ServiceRelativeFilePath(sv *gen.ServiceMetadata) string {
return filepath.Join(ServiceDir, ServiceFileName(sv))
} | go | func ServiceRelativeFilePath(sv *gen.ServiceMetadata) string {
return filepath.Join(ServiceDir, ServiceFileName(sv))
} | [
"func",
"ServiceRelativeFilePath",
"(",
"sv",
"*",
"gen",
".",
"ServiceMetadata",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"ServiceDir",
",",
"ServiceFileName",
"(",
"sv",
")",
")",
"\n",
"}"
]
| // ServiceRelativeFilePath returns the relative filepath to a service | [
"ServiceRelativeFilePath",
"returns",
"the",
"relative",
"filepath",
"to",
"a",
"service"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/gen/golang/path.go#L33-L35 |
9,256 | brutella/hc | hap/listener.go | NewTCPListener | func NewTCPListener(l *net.TCPListener, context Context) *TCPListener {
return &TCPListener{l, context}
} | go | func NewTCPListener(l *net.TCPListener, context Context) *TCPListener {
return &TCPListener{l, context}
} | [
"func",
"NewTCPListener",
"(",
"l",
"*",
"net",
".",
"TCPListener",
",",
"context",
"Context",
")",
"*",
"TCPListener",
"{",
"return",
"&",
"TCPListener",
"{",
"l",
",",
"context",
"}",
"\n",
"}"
]
| // NewTCPListener returns a new hap tcp listener. | [
"NewTCPListener",
"returns",
"a",
"new",
"hap",
"tcp",
"listener",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/listener.go#L14-L16 |
9,257 | brutella/hc | hap/listener.go | Accept | func (l *TCPListener) Accept() (c net.Conn, err error) {
conn, err := l.AcceptTCP()
if err != nil {
return
}
// TODO(brutella) Check if we should use tcp keepalive
// conn.SetKeepAlive(true)
// conn.SetKeepAlivePeriod(3 * time.Minute)
hapConn := NewConnection(conn, l.context)
return hapConn, err
} | go | func (l *TCPListener) Accept() (c net.Conn, err error) {
conn, err := l.AcceptTCP()
if err != nil {
return
}
// TODO(brutella) Check if we should use tcp keepalive
// conn.SetKeepAlive(true)
// conn.SetKeepAlivePeriod(3 * time.Minute)
hapConn := NewConnection(conn, l.context)
return hapConn, err
} | [
"func",
"(",
"l",
"*",
"TCPListener",
")",
"Accept",
"(",
")",
"(",
"c",
"net",
".",
"Conn",
",",
"err",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"l",
".",
"AcceptTCP",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// TODO(brutella) Check if we should use tcp keepalive",
"// conn.SetKeepAlive(true)",
"// conn.SetKeepAlivePeriod(3 * time.Minute)",
"hapConn",
":=",
"NewConnection",
"(",
"conn",
",",
"l",
".",
"context",
")",
"\n\n",
"return",
"hapConn",
",",
"err",
"\n",
"}"
]
| // Accept creates and returns a Connection. | [
"Accept",
"creates",
"and",
"returns",
"a",
"Connection",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/listener.go#L19-L31 |
9,258 | brutella/hc | accessory/camera.go | NewCamera | func NewCamera(info Info) *Camera {
acc := Camera{}
acc.Accessory = New(info, TypeIPCamera)
acc.Control = service.NewCameraControl()
acc.AddService(acc.Control.Service)
// TODO (mah) a camera must support at least 2 rtp streams
acc.StreamManagement1 = service.NewCameraRTPStreamManagement()
acc.StreamManagement2 = service.NewCameraRTPStreamManagement()
acc.AddService(acc.StreamManagement1.Service)
// acc.AddService(acc.StreamManagement2.Service)
return &acc
} | go | func NewCamera(info Info) *Camera {
acc := Camera{}
acc.Accessory = New(info, TypeIPCamera)
acc.Control = service.NewCameraControl()
acc.AddService(acc.Control.Service)
// TODO (mah) a camera must support at least 2 rtp streams
acc.StreamManagement1 = service.NewCameraRTPStreamManagement()
acc.StreamManagement2 = service.NewCameraRTPStreamManagement()
acc.AddService(acc.StreamManagement1.Service)
// acc.AddService(acc.StreamManagement2.Service)
return &acc
} | [
"func",
"NewCamera",
"(",
"info",
"Info",
")",
"*",
"Camera",
"{",
"acc",
":=",
"Camera",
"{",
"}",
"\n",
"acc",
".",
"Accessory",
"=",
"New",
"(",
"info",
",",
"TypeIPCamera",
")",
"\n",
"acc",
".",
"Control",
"=",
"service",
".",
"NewCameraControl",
"(",
")",
"\n",
"acc",
".",
"AddService",
"(",
"acc",
".",
"Control",
".",
"Service",
")",
"\n\n",
"// TODO (mah) a camera must support at least 2 rtp streams",
"acc",
".",
"StreamManagement1",
"=",
"service",
".",
"NewCameraRTPStreamManagement",
"(",
")",
"\n",
"acc",
".",
"StreamManagement2",
"=",
"service",
".",
"NewCameraRTPStreamManagement",
"(",
")",
"\n",
"acc",
".",
"AddService",
"(",
"acc",
".",
"StreamManagement1",
".",
"Service",
")",
"\n",
"// acc.AddService(acc.StreamManagement2.Service)",
"return",
"&",
"acc",
"\n",
"}"
]
| // NewCamera returns an IP camera accessory. | [
"NewCamera",
"returns",
"an",
"IP",
"camera",
"accessory",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/camera.go#L16-L29 |
9,259 | brutella/hc | util/rand.go | RandomHexString | func RandomHexString() string {
var b [16]byte
// Read might block
// > crypto/rand: blocked for 60 seconds waiting to read random data from the kernel
// > https://github.com/golang/go/commit/1961d8d72a53e780effa18bfa8dbe4e4282df0b2
_, err := rand.Read(b[:])
if err != nil {
panic(err)
}
var out [32]byte
for i := 0; i < len(b); i++ {
out[i*2] = btoh((b[i] >> 4) & 0xF)
out[i*2+1] = btoh(b[i] & 0xF)
}
return string(out[:])
} | go | func RandomHexString() string {
var b [16]byte
// Read might block
// > crypto/rand: blocked for 60 seconds waiting to read random data from the kernel
// > https://github.com/golang/go/commit/1961d8d72a53e780effa18bfa8dbe4e4282df0b2
_, err := rand.Read(b[:])
if err != nil {
panic(err)
}
var out [32]byte
for i := 0; i < len(b); i++ {
out[i*2] = btoh((b[i] >> 4) & 0xF)
out[i*2+1] = btoh(b[i] & 0xF)
}
return string(out[:])
} | [
"func",
"RandomHexString",
"(",
")",
"string",
"{",
"var",
"b",
"[",
"16",
"]",
"byte",
"\n",
"// Read might block",
"// > crypto/rand: blocked for 60 seconds waiting to read random data from the kernel",
"// > https://github.com/golang/go/commit/1961d8d72a53e780effa18bfa8dbe4e4282df0b2",
"_",
",",
"err",
":=",
"rand",
".",
"Read",
"(",
"b",
"[",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"var",
"out",
"[",
"32",
"]",
"byte",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"b",
")",
";",
"i",
"++",
"{",
"out",
"[",
"i",
"*",
"2",
"]",
"=",
"btoh",
"(",
"(",
"b",
"[",
"i",
"]",
">>",
"4",
")",
"&",
"0xF",
")",
"\n",
"out",
"[",
"i",
"*",
"2",
"+",
"1",
"]",
"=",
"btoh",
"(",
"b",
"[",
"i",
"]",
"&",
"0xF",
")",
"\n",
"}",
"\n",
"return",
"string",
"(",
"out",
"[",
":",
"]",
")",
"\n",
"}"
]
| // RandomHexString returns a random hex string. | [
"RandomHexString",
"returns",
"a",
"random",
"hex",
"string",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/util/rand.go#L8-L23 |
9,260 | brutella/hc | hap/connection.go | NewConnection | func NewConnection(connection net.Conn, context Context) *Connection {
conn := &Connection{
connection: connection,
context: context,
}
// Setup new session for the connection
session := NewSession(conn)
context.SetSessionForConnection(session, conn)
return conn
} | go | func NewConnection(connection net.Conn, context Context) *Connection {
conn := &Connection{
connection: connection,
context: context,
}
// Setup new session for the connection
session := NewSession(conn)
context.SetSessionForConnection(session, conn)
return conn
} | [
"func",
"NewConnection",
"(",
"connection",
"net",
".",
"Conn",
",",
"context",
"Context",
")",
"*",
"Connection",
"{",
"conn",
":=",
"&",
"Connection",
"{",
"connection",
":",
"connection",
",",
"context",
":",
"context",
",",
"}",
"\n\n",
"// Setup new session for the connection",
"session",
":=",
"NewSession",
"(",
"conn",
")",
"\n",
"context",
".",
"SetSessionForConnection",
"(",
"session",
",",
"conn",
")",
"\n\n",
"return",
"conn",
"\n",
"}"
]
| // NewConnection returns a hap connection. | [
"NewConnection",
"returns",
"a",
"hap",
"connection",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/connection.go#L31-L42 |
9,261 | brutella/hc | hap/connection.go | EncryptedWrite | func (con *Connection) EncryptedWrite(b []byte) (int, error) {
var buffer bytes.Buffer
buffer.Write(b)
encrypted, err := con.getEncrypter().Encrypt(&buffer)
if err != nil {
log.Info.Panic("Encryption failed:", err)
err = con.connection.Close()
return 0, err
}
encryptedBytes, err := ioutil.ReadAll(encrypted)
n, err := con.connection.Write(encryptedBytes)
return n, err
} | go | func (con *Connection) EncryptedWrite(b []byte) (int, error) {
var buffer bytes.Buffer
buffer.Write(b)
encrypted, err := con.getEncrypter().Encrypt(&buffer)
if err != nil {
log.Info.Panic("Encryption failed:", err)
err = con.connection.Close()
return 0, err
}
encryptedBytes, err := ioutil.ReadAll(encrypted)
n, err := con.connection.Write(encryptedBytes)
return n, err
} | [
"func",
"(",
"con",
"*",
"Connection",
")",
"EncryptedWrite",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n",
"buffer",
".",
"Write",
"(",
"b",
")",
"\n",
"encrypted",
",",
"err",
":=",
"con",
".",
"getEncrypter",
"(",
")",
".",
"Encrypt",
"(",
"&",
"buffer",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Info",
".",
"Panic",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"err",
"=",
"con",
".",
"connection",
".",
"Close",
"(",
")",
"\n",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"encryptedBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"encrypted",
")",
"\n",
"n",
",",
"err",
":=",
"con",
".",
"connection",
".",
"Write",
"(",
"encryptedBytes",
")",
"\n\n",
"return",
"n",
",",
"err",
"\n",
"}"
]
| // EncryptedWrite encrypts and writes bytes to the connection.
// The method returns the number of written bytes and an error when writing failed. | [
"EncryptedWrite",
"encrypts",
"and",
"writes",
"bytes",
"to",
"the",
"connection",
".",
"The",
"method",
"returns",
"the",
"number",
"of",
"written",
"bytes",
"and",
"an",
"error",
"when",
"writing",
"failed",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/connection.go#L46-L61 |
9,262 | brutella/hc | hap/connection.go | DecryptedRead | func (con *Connection) DecryptedRead(b []byte) (int, error) {
if con.readBuffer == nil {
buffered := bufio.NewReader(con.connection)
decrypted, err := con.getDecrypter().Decrypt(buffered)
if err != nil {
if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
// Ignore timeout error #77
} else {
log.Debug.Println("Decryption failed:", err)
err = con.connection.Close()
}
return 0, err
}
con.readBuffer = decrypted
}
n, err := con.readBuffer.Read(b)
if n < len(b) || err == io.EOF {
con.readBuffer = nil
}
return n, err
} | go | func (con *Connection) DecryptedRead(b []byte) (int, error) {
if con.readBuffer == nil {
buffered := bufio.NewReader(con.connection)
decrypted, err := con.getDecrypter().Decrypt(buffered)
if err != nil {
if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
// Ignore timeout error #77
} else {
log.Debug.Println("Decryption failed:", err)
err = con.connection.Close()
}
return 0, err
}
con.readBuffer = decrypted
}
n, err := con.readBuffer.Read(b)
if n < len(b) || err == io.EOF {
con.readBuffer = nil
}
return n, err
} | [
"func",
"(",
"con",
"*",
"Connection",
")",
"DecryptedRead",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"con",
".",
"readBuffer",
"==",
"nil",
"{",
"buffered",
":=",
"bufio",
".",
"NewReader",
"(",
"con",
".",
"connection",
")",
"\n",
"decrypted",
",",
"err",
":=",
"con",
".",
"getDecrypter",
"(",
")",
".",
"Decrypt",
"(",
"buffered",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"neterr",
",",
"ok",
":=",
"err",
".",
"(",
"net",
".",
"Error",
")",
";",
"ok",
"&&",
"neterr",
".",
"Timeout",
"(",
")",
"{",
"// Ignore timeout error #77",
"}",
"else",
"{",
"log",
".",
"Debug",
".",
"Println",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"err",
"=",
"con",
".",
"connection",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"con",
".",
"readBuffer",
"=",
"decrypted",
"\n",
"}",
"\n\n",
"n",
",",
"err",
":=",
"con",
".",
"readBuffer",
".",
"Read",
"(",
"b",
")",
"\n\n",
"if",
"n",
"<",
"len",
"(",
"b",
")",
"||",
"err",
"==",
"io",
".",
"EOF",
"{",
"con",
".",
"readBuffer",
"=",
"nil",
"\n",
"}",
"\n\n",
"return",
"n",
",",
"err",
"\n",
"}"
]
| // DecryptedRead reads and decrypts bytes from the connection.
// The method returns the number of read bytes and an error when reading failed. | [
"DecryptedRead",
"reads",
"and",
"decrypts",
"bytes",
"from",
"the",
"connection",
".",
"The",
"method",
"returns",
"the",
"number",
"of",
"read",
"bytes",
"and",
"an",
"error",
"when",
"reading",
"failed",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/connection.go#L65-L89 |
9,263 | brutella/hc | hap/connection.go | Write | func (con *Connection) Write(b []byte) (int, error) {
if con.getEncrypter() != nil {
return con.EncryptedWrite(b)
}
return con.connection.Write(b)
} | go | func (con *Connection) Write(b []byte) (int, error) {
if con.getEncrypter() != nil {
return con.EncryptedWrite(b)
}
return con.connection.Write(b)
} | [
"func",
"(",
"con",
"*",
"Connection",
")",
"Write",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"con",
".",
"getEncrypter",
"(",
")",
"!=",
"nil",
"{",
"return",
"con",
".",
"EncryptedWrite",
"(",
"b",
")",
"\n",
"}",
"\n\n",
"return",
"con",
".",
"connection",
".",
"Write",
"(",
"b",
")",
"\n",
"}"
]
| // Write writes bytes to the connection.
// The written bytes are encrypted when possible. | [
"Write",
"writes",
"bytes",
"to",
"the",
"connection",
".",
"The",
"written",
"bytes",
"are",
"encrypted",
"when",
"possible",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/connection.go#L93-L99 |
9,264 | brutella/hc | hap/connection.go | Read | func (con *Connection) Read(b []byte) (int, error) {
if con.getDecrypter() != nil {
return con.DecryptedRead(b)
}
return con.connection.Read(b)
} | go | func (con *Connection) Read(b []byte) (int, error) {
if con.getDecrypter() != nil {
return con.DecryptedRead(b)
}
return con.connection.Read(b)
} | [
"func",
"(",
"con",
"*",
"Connection",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"con",
".",
"getDecrypter",
"(",
")",
"!=",
"nil",
"{",
"return",
"con",
".",
"DecryptedRead",
"(",
"b",
")",
"\n",
"}",
"\n\n",
"return",
"con",
".",
"connection",
".",
"Read",
"(",
"b",
")",
"\n",
"}"
]
| // Read reads bytes from the connection. The read bytes are decrypted when possible. | [
"Read",
"reads",
"bytes",
"from",
"the",
"connection",
".",
"The",
"read",
"bytes",
"are",
"decrypted",
"when",
"possible",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/connection.go#L102-L108 |
9,265 | brutella/hc | hap/connection.go | Close | func (con *Connection) Close() error {
log.Debug.Println("Close connection and remove session")
// Remove session from the context
con.context.DeleteSessionForConnection(con.connection)
return con.connection.Close()
} | go | func (con *Connection) Close() error {
log.Debug.Println("Close connection and remove session")
// Remove session from the context
con.context.DeleteSessionForConnection(con.connection)
return con.connection.Close()
} | [
"func",
"(",
"con",
"*",
"Connection",
")",
"Close",
"(",
")",
"error",
"{",
"log",
".",
"Debug",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n\n",
"// Remove session from the context",
"con",
".",
"context",
".",
"DeleteSessionForConnection",
"(",
"con",
".",
"connection",
")",
"\n\n",
"return",
"con",
".",
"connection",
".",
"Close",
"(",
")",
"\n",
"}"
]
| // Close closes the connection and deletes the related session from the context. | [
"Close",
"closes",
"the",
"connection",
"and",
"deletes",
"the",
"related",
"session",
"from",
"the",
"context",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/connection.go#L111-L118 |
9,266 | brutella/hc | hap/connection.go | getEncrypter | func (con *Connection) getEncrypter() crypto.Encrypter {
session := con.context.GetSessionForConnection(con.connection)
if session != nil {
return session.Encrypter()
}
return nil
} | go | func (con *Connection) getEncrypter() crypto.Encrypter {
session := con.context.GetSessionForConnection(con.connection)
if session != nil {
return session.Encrypter()
}
return nil
} | [
"func",
"(",
"con",
"*",
"Connection",
")",
"getEncrypter",
"(",
")",
"crypto",
".",
"Encrypter",
"{",
"session",
":=",
"con",
".",
"context",
".",
"GetSessionForConnection",
"(",
"con",
".",
"connection",
")",
"\n",
"if",
"session",
"!=",
"nil",
"{",
"return",
"session",
".",
"Encrypter",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // getEncrypter returns the session's Encrypter, otherwise nil | [
"getEncrypter",
"returns",
"the",
"session",
"s",
"Encrypter",
"otherwise",
"nil"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/connection.go#L146-L153 |
9,267 | brutella/hc | hap/connection.go | getDecrypter | func (con *Connection) getDecrypter() crypto.Decrypter {
session := con.context.GetSessionForConnection(con.connection)
if session != nil {
return session.Decrypter()
}
return nil
} | go | func (con *Connection) getDecrypter() crypto.Decrypter {
session := con.context.GetSessionForConnection(con.connection)
if session != nil {
return session.Decrypter()
}
return nil
} | [
"func",
"(",
"con",
"*",
"Connection",
")",
"getDecrypter",
"(",
")",
"crypto",
".",
"Decrypter",
"{",
"session",
":=",
"con",
".",
"context",
".",
"GetSessionForConnection",
"(",
"con",
".",
"connection",
")",
"\n",
"if",
"session",
"!=",
"nil",
"{",
"return",
"session",
".",
"Decrypter",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // getDecrypter returns the session's Decrypter, otherwise nil | [
"getDecrypter",
"returns",
"the",
"session",
"s",
"Decrypter",
"otherwise",
"nil"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/connection.go#L156-L163 |
9,268 | brutella/hc | hap/device.go | NewDevice | func NewDevice(name string, database db.Database) (Device, error) {
var e db.Entity
var err error
if e, err = database.EntityWithName(name); err != nil {
if e, err = db.NewRandomEntityWithName(name); err == nil {
err = database.SaveEntity(e)
}
}
return &device{e}, err
} | go | func NewDevice(name string, database db.Database) (Device, error) {
var e db.Entity
var err error
if e, err = database.EntityWithName(name); err != nil {
if e, err = db.NewRandomEntityWithName(name); err == nil {
err = database.SaveEntity(e)
}
}
return &device{e}, err
} | [
"func",
"NewDevice",
"(",
"name",
"string",
",",
"database",
"db",
".",
"Database",
")",
"(",
"Device",
",",
"error",
")",
"{",
"var",
"e",
"db",
".",
"Entity",
"\n",
"var",
"err",
"error",
"\n\n",
"if",
"e",
",",
"err",
"=",
"database",
".",
"EntityWithName",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"e",
",",
"err",
"=",
"db",
".",
"NewRandomEntityWithName",
"(",
"name",
")",
";",
"err",
"==",
"nil",
"{",
"err",
"=",
"database",
".",
"SaveEntity",
"(",
"e",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"device",
"{",
"e",
"}",
",",
"err",
"\n",
"}"
]
| // NewDevice returns a client for a specific name either loaded from the database
// or newly created. | [
"NewDevice",
"returns",
"a",
"client",
"for",
"a",
"specific",
"name",
"either",
"loaded",
"from",
"the",
"database",
"or",
"newly",
"created",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/device.go#L25-L36 |
9,269 | brutella/hc | gen/golang/characteristic.go | CharacteristicGoCode | func CharacteristicGoCode(char *gen.CharacteristicMetadata) ([]byte, error) {
var err error
var buf bytes.Buffer
data := NewCharacteristic(char)
t := template.New("Test Template")
t, err = t.Parse(CharStructTemplate)
t.Execute(&buf, data)
return buf.Bytes(), err
} | go | func CharacteristicGoCode(char *gen.CharacteristicMetadata) ([]byte, error) {
var err error
var buf bytes.Buffer
data := NewCharacteristic(char)
t := template.New("Test Template")
t, err = t.Parse(CharStructTemplate)
t.Execute(&buf, data)
return buf.Bytes(), err
} | [
"func",
"CharacteristicGoCode",
"(",
"char",
"*",
"gen",
".",
"CharacteristicMetadata",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n\n",
"data",
":=",
"NewCharacteristic",
"(",
"char",
")",
"\n\n",
"t",
":=",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
"\n\n",
"t",
",",
"err",
"=",
"t",
".",
"Parse",
"(",
"CharStructTemplate",
")",
"\n",
"t",
".",
"Execute",
"(",
"&",
"buf",
",",
"data",
")",
"\n\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"err",
"\n",
"}"
]
| // CharacteristicGoCode returns the o code for a characteristic file | [
"CharacteristicGoCode",
"returns",
"the",
"o",
"code",
"for",
"a",
"characteristic",
"file"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/gen/golang/characteristic.go#L154-L166 |
9,270 | brutella/hc | gen/golang/characteristic.go | isReadable | func isReadable(char *gen.CharacteristicMetadata) bool {
for _, perm := range char.Properties {
if perm == "read" {
return true
}
}
return false
} | go | func isReadable(char *gen.CharacteristicMetadata) bool {
for _, perm := range char.Properties {
if perm == "read" {
return true
}
}
return false
} | [
"func",
"isReadable",
"(",
"char",
"*",
"gen",
".",
"CharacteristicMetadata",
")",
"bool",
"{",
"for",
"_",
",",
"perm",
":=",
"range",
"char",
".",
"Properties",
"{",
"if",
"perm",
"==",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
]
| // isReadable returns true the characteristic contains the readable property | [
"isReadable",
"returns",
"true",
"the",
"characteristic",
"contains",
"the",
"readable",
"property"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/gen/golang/characteristic.go#L204-L212 |
9,271 | brutella/hc | gen/golang/characteristic.go | minifyUUID | func minifyUUID(s string) string {
authRegexp := regexp.MustCompile(`^([0-9a-fA-F]*)`)
if str := authRegexp.FindString(s); len(str) > 0 {
return strings.TrimLeft(str, "0")
}
return s
} | go | func minifyUUID(s string) string {
authRegexp := regexp.MustCompile(`^([0-9a-fA-F]*)`)
if str := authRegexp.FindString(s); len(str) > 0 {
return strings.TrimLeft(str, "0")
}
return s
} | [
"func",
"minifyUUID",
"(",
"s",
"string",
")",
"string",
"{",
"authRegexp",
":=",
"regexp",
".",
"MustCompile",
"(",
"`^([0-9a-fA-F]*)`",
")",
"\n",
"if",
"str",
":=",
"authRegexp",
".",
"FindString",
"(",
"s",
")",
";",
"len",
"(",
"str",
")",
">",
"0",
"{",
"return",
"strings",
".",
"TrimLeft",
"(",
"str",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"s",
"\n",
"}"
]
| // minifyUUID returns a minified version of s by removing unneeded characters.
// For example the UUID "0000008C-0000-1000-8000-0026BB765291" the Window Covering
// service will be minified to "8C". | [
"minifyUUID",
"returns",
"a",
"minified",
"version",
"of",
"s",
"by",
"removing",
"unneeded",
"characters",
".",
"For",
"example",
"the",
"UUID",
"0000008C",
"-",
"0000",
"-",
"1000",
"-",
"8000",
"-",
"0026BB765291",
"the",
"Window",
"Covering",
"service",
"will",
"be",
"minified",
"to",
"8C",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/gen/golang/characteristic.go#L243-L250 |
9,272 | brutella/hc | accessory/switch.go | NewSwitch | func NewSwitch(info Info) *Switch {
acc := Switch{}
acc.Accessory = New(info, TypeSwitch)
acc.Switch = service.NewSwitch()
acc.AddService(acc.Switch.Service)
return &acc
} | go | func NewSwitch(info Info) *Switch {
acc := Switch{}
acc.Accessory = New(info, TypeSwitch)
acc.Switch = service.NewSwitch()
acc.AddService(acc.Switch.Service)
return &acc
} | [
"func",
"NewSwitch",
"(",
"info",
"Info",
")",
"*",
"Switch",
"{",
"acc",
":=",
"Switch",
"{",
"}",
"\n",
"acc",
".",
"Accessory",
"=",
"New",
"(",
"info",
",",
"TypeSwitch",
")",
"\n",
"acc",
".",
"Switch",
"=",
"service",
".",
"NewSwitch",
"(",
")",
"\n",
"acc",
".",
"AddService",
"(",
"acc",
".",
"Switch",
".",
"Service",
")",
"\n\n",
"return",
"&",
"acc",
"\n",
"}"
]
| // NewSwitch returns a switch which implements model.Switch. | [
"NewSwitch",
"returns",
"a",
"switch",
"which",
"implements",
"model",
".",
"Switch",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/accessory/switch.go#L13-L20 |
9,273 | brutella/hc | hap/pair/setup_client_session.go | NewSetupClientSession | func NewSetupClientSession(username string, pin string) *SetupClientSession {
rp, _ := srp.NewSRP(SRPGroup, sha512.New, KeyDerivativeFuncRFC2945(sha512.New, []byte(username)))
client := rp.NewClientSession([]byte(username), []byte(pin))
hap := SetupClientSession{
session: client,
}
return &hap
} | go | func NewSetupClientSession(username string, pin string) *SetupClientSession {
rp, _ := srp.NewSRP(SRPGroup, sha512.New, KeyDerivativeFuncRFC2945(sha512.New, []byte(username)))
client := rp.NewClientSession([]byte(username), []byte(pin))
hap := SetupClientSession{
session: client,
}
return &hap
} | [
"func",
"NewSetupClientSession",
"(",
"username",
"string",
",",
"pin",
"string",
")",
"*",
"SetupClientSession",
"{",
"rp",
",",
"_",
":=",
"srp",
".",
"NewSRP",
"(",
"SRPGroup",
",",
"sha512",
".",
"New",
",",
"KeyDerivativeFuncRFC2945",
"(",
"sha512",
".",
"New",
",",
"[",
"]",
"byte",
"(",
"username",
")",
")",
")",
"\n\n",
"client",
":=",
"rp",
".",
"NewClientSession",
"(",
"[",
"]",
"byte",
"(",
"username",
")",
",",
"[",
"]",
"byte",
"(",
"pin",
")",
")",
"\n",
"hap",
":=",
"SetupClientSession",
"{",
"session",
":",
"client",
",",
"}",
"\n\n",
"return",
"&",
"hap",
"\n",
"}"
]
| // NewSetupClientSession returns a new setup client session | [
"NewSetupClientSession",
"returns",
"a",
"new",
"setup",
"client",
"session"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/setup_client_session.go#L20-L29 |
9,274 | brutella/hc | hap/pair/setup_client_session.go | GenerateKeys | func (s *SetupClientSession) GenerateKeys(salt []byte, otherPublicKey []byte) error {
privateKey, err := s.session.ComputeKey(salt, otherPublicKey)
if err == nil {
s.PublicKey = s.session.GetA()
s.PrivateKey = privateKey
s.Proof = s.session.ComputeAuthenticator()
}
return err
} | go | func (s *SetupClientSession) GenerateKeys(salt []byte, otherPublicKey []byte) error {
privateKey, err := s.session.ComputeKey(salt, otherPublicKey)
if err == nil {
s.PublicKey = s.session.GetA()
s.PrivateKey = privateKey
s.Proof = s.session.ComputeAuthenticator()
}
return err
} | [
"func",
"(",
"s",
"*",
"SetupClientSession",
")",
"GenerateKeys",
"(",
"salt",
"[",
"]",
"byte",
",",
"otherPublicKey",
"[",
"]",
"byte",
")",
"error",
"{",
"privateKey",
",",
"err",
":=",
"s",
".",
"session",
".",
"ComputeKey",
"(",
"salt",
",",
"otherPublicKey",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"s",
".",
"PublicKey",
"=",
"s",
".",
"session",
".",
"GetA",
"(",
")",
"\n",
"s",
".",
"PrivateKey",
"=",
"privateKey",
"\n",
"s",
".",
"Proof",
"=",
"s",
".",
"session",
".",
"ComputeAuthenticator",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // GenerateKeys generates public and private keys based on server's salt and public key. | [
"GenerateKeys",
"generates",
"public",
"and",
"private",
"keys",
"based",
"on",
"server",
"s",
"salt",
"and",
"public",
"key",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/setup_client_session.go#L32-L41 |
9,275 | brutella/hc | hap/pair/setup_client_session.go | IsServerProofValid | func (s *SetupClientSession) IsServerProofValid(proof []byte) bool {
return s.session.VerifyServerAuthenticator(proof)
} | go | func (s *SetupClientSession) IsServerProofValid(proof []byte) bool {
return s.session.VerifyServerAuthenticator(proof)
} | [
"func",
"(",
"s",
"*",
"SetupClientSession",
")",
"IsServerProofValid",
"(",
"proof",
"[",
"]",
"byte",
")",
"bool",
"{",
"return",
"s",
".",
"session",
".",
"VerifyServerAuthenticator",
"(",
"proof",
")",
"\n",
"}"
]
| // IsServerProofValid returns true when the server proof `M2` is valid. | [
"IsServerProofValid",
"returns",
"true",
"when",
"the",
"server",
"proof",
"M2",
"is",
"valid",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/setup_client_session.go#L44-L46 |
9,276 | brutella/hc | hap/pair/setup_client_session.go | SetupEncryptionKey | func (s *SetupClientSession) SetupEncryptionKey(salt []byte, info []byte) error {
hash, err := hkdf.Sha512(s.PrivateKey, salt, info)
if err == nil {
s.EncryptionKey = hash
}
return err
} | go | func (s *SetupClientSession) SetupEncryptionKey(salt []byte, info []byte) error {
hash, err := hkdf.Sha512(s.PrivateKey, salt, info)
if err == nil {
s.EncryptionKey = hash
}
return err
} | [
"func",
"(",
"s",
"*",
"SetupClientSession",
")",
"SetupEncryptionKey",
"(",
"salt",
"[",
"]",
"byte",
",",
"info",
"[",
"]",
"byte",
")",
"error",
"{",
"hash",
",",
"err",
":=",
"hkdf",
".",
"Sha512",
"(",
"s",
".",
"PrivateKey",
",",
"salt",
",",
"info",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"s",
".",
"EncryptionKey",
"=",
"hash",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // SetupEncryptionKey calculates encryption key `K` based on salt and info. | [
"SetupEncryptionKey",
"calculates",
"encryption",
"key",
"K",
"based",
"on",
"salt",
"and",
"info",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/setup_client_session.go#L49-L56 |
9,277 | brutella/hc | hap/chunked_writer.go | NewChunkedWriter | func NewChunkedWriter(wr io.Writer, chunk int) io.Writer {
return &chunkedWriter{wr, chunk}
} | go | func NewChunkedWriter(wr io.Writer, chunk int) io.Writer {
return &chunkedWriter{wr, chunk}
} | [
"func",
"NewChunkedWriter",
"(",
"wr",
"io",
".",
"Writer",
",",
"chunk",
"int",
")",
"io",
".",
"Writer",
"{",
"return",
"&",
"chunkedWriter",
"{",
"wr",
",",
"chunk",
"}",
"\n",
"}"
]
| // NewChunkedWriter returns a writer which writes bytes in chunkes of specified size. | [
"NewChunkedWriter",
"returns",
"a",
"writer",
"which",
"writes",
"bytes",
"in",
"chunkes",
"of",
"specified",
"size",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/chunked_writer.go#L13-L15 |
9,278 | brutella/hc | hap/endpoint/characteristics.go | NewCharacteristics | func NewCharacteristics(context hap.Context, c hap.CharacteristicsHandler, mutex *sync.Mutex) *Characteristics {
handler := Characteristics{
controller: c,
mutex: mutex,
context: context,
}
return &handler
} | go | func NewCharacteristics(context hap.Context, c hap.CharacteristicsHandler, mutex *sync.Mutex) *Characteristics {
handler := Characteristics{
controller: c,
mutex: mutex,
context: context,
}
return &handler
} | [
"func",
"NewCharacteristics",
"(",
"context",
"hap",
".",
"Context",
",",
"c",
"hap",
".",
"CharacteristicsHandler",
",",
"mutex",
"*",
"sync",
".",
"Mutex",
")",
"*",
"Characteristics",
"{",
"handler",
":=",
"Characteristics",
"{",
"controller",
":",
"c",
",",
"mutex",
":",
"mutex",
",",
"context",
":",
"context",
",",
"}",
"\n\n",
"return",
"&",
"handler",
"\n",
"}"
]
| // NewCharacteristics returns a new handler for characteristics endpoint | [
"NewCharacteristics",
"returns",
"a",
"new",
"handler",
"for",
"characteristics",
"endpoint"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/endpoint/characteristics.go#L25-L33 |
9,279 | brutella/hc | config.go | txtRecords | func (cfg Config) txtRecords() map[string]string {
return map[string]string{
"pv": cfg.protocol,
"id": cfg.id,
"c#": fmt.Sprintf("%d", cfg.version),
"s#": fmt.Sprintf("%d", cfg.state),
"sf": fmt.Sprintf("%d", to.Int64(cfg.discoverable)),
"ff": fmt.Sprintf("%d", to.Int64(cfg.mfiCompliant)),
"md": cfg.name,
"ci": fmt.Sprintf("%d", cfg.categoryId),
}
} | go | func (cfg Config) txtRecords() map[string]string {
return map[string]string{
"pv": cfg.protocol,
"id": cfg.id,
"c#": fmt.Sprintf("%d", cfg.version),
"s#": fmt.Sprintf("%d", cfg.state),
"sf": fmt.Sprintf("%d", to.Int64(cfg.discoverable)),
"ff": fmt.Sprintf("%d", to.Int64(cfg.mfiCompliant)),
"md": cfg.name,
"ci": fmt.Sprintf("%d", cfg.categoryId),
}
} | [
"func",
"(",
"cfg",
"Config",
")",
"txtRecords",
"(",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"cfg",
".",
"protocol",
",",
"\"",
"\"",
":",
"cfg",
".",
"id",
",",
"\"",
"\"",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cfg",
".",
"version",
")",
",",
"\"",
"\"",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cfg",
".",
"state",
")",
",",
"\"",
"\"",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"to",
".",
"Int64",
"(",
"cfg",
".",
"discoverable",
")",
")",
",",
"\"",
"\"",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"to",
".",
"Int64",
"(",
"cfg",
".",
"mfiCompliant",
")",
")",
",",
"\"",
"\"",
":",
"cfg",
".",
"name",
",",
"\"",
"\"",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cfg",
".",
"categoryId",
")",
",",
"}",
"\n",
"}"
]
| // txtRecords returns the config formatted as mDNS txt records | [
"txtRecords",
"returns",
"the",
"config",
"formatted",
"as",
"mDNS",
"txt",
"records"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/config.go#L58-L69 |
9,280 | brutella/hc | config.go | load | func (cfg *Config) load(storage util.Storage) {
if b, err := storage.Get("uuid"); err == nil && len(b) > 0 {
cfg.id = string(b)
}
if b, err := storage.Get("version"); err == nil && len(b) > 0 {
cfg.version = to.Int64(string(b))
}
if b, err := storage.Get("configHash"); err == nil && len(b) > 0 {
cfg.configHash = b
}
} | go | func (cfg *Config) load(storage util.Storage) {
if b, err := storage.Get("uuid"); err == nil && len(b) > 0 {
cfg.id = string(b)
}
if b, err := storage.Get("version"); err == nil && len(b) > 0 {
cfg.version = to.Int64(string(b))
}
if b, err := storage.Get("configHash"); err == nil && len(b) > 0 {
cfg.configHash = b
}
} | [
"func",
"(",
"cfg",
"*",
"Config",
")",
"load",
"(",
"storage",
"util",
".",
"Storage",
")",
"{",
"if",
"b",
",",
"err",
":=",
"storage",
".",
"Get",
"(",
"\"",
"\"",
")",
";",
"err",
"==",
"nil",
"&&",
"len",
"(",
"b",
")",
">",
"0",
"{",
"cfg",
".",
"id",
"=",
"string",
"(",
"b",
")",
"\n",
"}",
"\n\n",
"if",
"b",
",",
"err",
":=",
"storage",
".",
"Get",
"(",
"\"",
"\"",
")",
";",
"err",
"==",
"nil",
"&&",
"len",
"(",
"b",
")",
">",
"0",
"{",
"cfg",
".",
"version",
"=",
"to",
".",
"Int64",
"(",
"string",
"(",
"b",
")",
")",
"\n",
"}",
"\n\n",
"if",
"b",
",",
"err",
":=",
"storage",
".",
"Get",
"(",
"\"",
"\"",
")",
";",
"err",
"==",
"nil",
"&&",
"len",
"(",
"b",
")",
">",
"0",
"{",
"cfg",
".",
"configHash",
"=",
"b",
"\n",
"}",
"\n",
"}"
]
| // loads load the id, version and config hash | [
"loads",
"load",
"the",
"id",
"version",
"and",
"config",
"hash"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/config.go#L72-L84 |
9,281 | brutella/hc | config.go | save | func (cfg *Config) save(storage util.Storage) {
storage.Set("uuid", []byte(cfg.id))
storage.Set("version", []byte(fmt.Sprintf("%d", cfg.version)))
storage.Set("configHash", []byte(cfg.configHash))
} | go | func (cfg *Config) save(storage util.Storage) {
storage.Set("uuid", []byte(cfg.id))
storage.Set("version", []byte(fmt.Sprintf("%d", cfg.version)))
storage.Set("configHash", []byte(cfg.configHash))
} | [
"func",
"(",
"cfg",
"*",
"Config",
")",
"save",
"(",
"storage",
"util",
".",
"Storage",
")",
"{",
"storage",
".",
"Set",
"(",
"\"",
"\"",
",",
"[",
"]",
"byte",
"(",
"cfg",
".",
"id",
")",
")",
"\n",
"storage",
".",
"Set",
"(",
"\"",
"\"",
",",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cfg",
".",
"version",
")",
")",
")",
"\n",
"storage",
".",
"Set",
"(",
"\"",
"\"",
",",
"[",
"]",
"byte",
"(",
"cfg",
".",
"configHash",
")",
")",
"\n",
"}"
]
| // save stores the id, version and config | [
"save",
"stores",
"the",
"id",
"version",
"and",
"config"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/config.go#L87-L91 |
9,282 | brutella/hc | config.go | merge | func (cfg *Config) merge(other Config) {
if dir := other.StoragePath; len(dir) > 0 {
cfg.StoragePath = dir
}
if pin := other.Pin; len(pin) > 0 {
cfg.Pin = pin
}
if port := other.Port; len(port) > 0 {
cfg.Port = ":" + port
}
if ip := other.IP; len(ip) > 0 {
cfg.IP = ip
}
} | go | func (cfg *Config) merge(other Config) {
if dir := other.StoragePath; len(dir) > 0 {
cfg.StoragePath = dir
}
if pin := other.Pin; len(pin) > 0 {
cfg.Pin = pin
}
if port := other.Port; len(port) > 0 {
cfg.Port = ":" + port
}
if ip := other.IP; len(ip) > 0 {
cfg.IP = ip
}
} | [
"func",
"(",
"cfg",
"*",
"Config",
")",
"merge",
"(",
"other",
"Config",
")",
"{",
"if",
"dir",
":=",
"other",
".",
"StoragePath",
";",
"len",
"(",
"dir",
")",
">",
"0",
"{",
"cfg",
".",
"StoragePath",
"=",
"dir",
"\n",
"}",
"\n\n",
"if",
"pin",
":=",
"other",
".",
"Pin",
";",
"len",
"(",
"pin",
")",
">",
"0",
"{",
"cfg",
".",
"Pin",
"=",
"pin",
"\n",
"}",
"\n\n",
"if",
"port",
":=",
"other",
".",
"Port",
";",
"len",
"(",
"port",
")",
">",
"0",
"{",
"cfg",
".",
"Port",
"=",
"\"",
"\"",
"+",
"port",
"\n",
"}",
"\n\n",
"if",
"ip",
":=",
"other",
".",
"IP",
";",
"len",
"(",
"ip",
")",
">",
"0",
"{",
"cfg",
".",
"IP",
"=",
"ip",
"\n",
"}",
"\n",
"}"
]
| // merge updates the StoragePath, Pin, Port and IP fields of the receiver from other. | [
"merge",
"updates",
"the",
"StoragePath",
"Pin",
"Port",
"and",
"IP",
"fields",
"of",
"the",
"receiver",
"from",
"other",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/config.go#L94-L110 |
9,283 | brutella/hc | config.go | updateConfigHash | func (cfg *Config) updateConfigHash(hash []byte) {
if cfg.configHash != nil && reflect.DeepEqual(hash, cfg.configHash) == false {
cfg.version += 1
}
cfg.configHash = hash
} | go | func (cfg *Config) updateConfigHash(hash []byte) {
if cfg.configHash != nil && reflect.DeepEqual(hash, cfg.configHash) == false {
cfg.version += 1
}
cfg.configHash = hash
} | [
"func",
"(",
"cfg",
"*",
"Config",
")",
"updateConfigHash",
"(",
"hash",
"[",
"]",
"byte",
")",
"{",
"if",
"cfg",
".",
"configHash",
"!=",
"nil",
"&&",
"reflect",
".",
"DeepEqual",
"(",
"hash",
",",
"cfg",
".",
"configHash",
")",
"==",
"false",
"{",
"cfg",
".",
"version",
"+=",
"1",
"\n",
"}",
"\n\n",
"cfg",
".",
"configHash",
"=",
"hash",
"\n",
"}"
]
| // updateConfigHash updates configHash of the receiver and increments version
// if new hash is different than old one. | [
"updateConfigHash",
"updates",
"configHash",
"of",
"the",
"receiver",
"and",
"increments",
"version",
"if",
"new",
"hash",
"is",
"different",
"than",
"old",
"one",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/config.go#L114-L120 |
9,284 | brutella/hc | util/file_storage.go | NewTempFileStorage | func NewTempFileStorage() (Storage, error) {
dir := RandomHexString()
return NewFileStorage(path.Join(os.TempDir(), dir))
} | go | func NewTempFileStorage() (Storage, error) {
dir := RandomHexString()
return NewFileStorage(path.Join(os.TempDir(), dir))
} | [
"func",
"NewTempFileStorage",
"(",
")",
"(",
"Storage",
",",
"error",
")",
"{",
"dir",
":=",
"RandomHexString",
"(",
")",
"\n",
"return",
"NewFileStorage",
"(",
"path",
".",
"Join",
"(",
"os",
".",
"TempDir",
"(",
")",
",",
"dir",
")",
")",
"\n",
"}"
]
| // NewTempFileStorage returns a new storage inside temporary folder. | [
"NewTempFileStorage",
"returns",
"a",
"new",
"storage",
"inside",
"temporary",
"folder",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/util/file_storage.go#L17-L20 |
9,285 | brutella/hc | util/file_storage.go | NewFileStorage | func NewFileStorage(dir string) (Storage, error) {
path, err := filepath.Abs(dir)
if err != nil {
return nil, err
}
// Why 0777?
// Read http://unix.stackexchange.com/questions/21251/why-do-directories-need-the-executable-x-permission-to-be-opened
err = os.MkdirAll(path, 0777)
return &fileStorage{dirPath: path}, err
} | go | func NewFileStorage(dir string) (Storage, error) {
path, err := filepath.Abs(dir)
if err != nil {
return nil, err
}
// Why 0777?
// Read http://unix.stackexchange.com/questions/21251/why-do-directories-need-the-executable-x-permission-to-be-opened
err = os.MkdirAll(path, 0777)
return &fileStorage{dirPath: path}, err
} | [
"func",
"NewFileStorage",
"(",
"dir",
"string",
")",
"(",
"Storage",
",",
"error",
")",
"{",
"path",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Why 0777?",
"// Read http://unix.stackexchange.com/questions/21251/why-do-directories-need-the-executable-x-permission-to-be-opened",
"err",
"=",
"os",
".",
"MkdirAll",
"(",
"path",
",",
"0777",
")",
"\n",
"return",
"&",
"fileStorage",
"{",
"dirPath",
":",
"path",
"}",
",",
"err",
"\n",
"}"
]
| // NewFileStorage create a file storage for the specified directory.
// The folder is created if necessary. Every key-value pair is stored in a seperate file. | [
"NewFileStorage",
"create",
"a",
"file",
"storage",
"for",
"the",
"specified",
"directory",
".",
"The",
"folder",
"is",
"created",
"if",
"necessary",
".",
"Every",
"key",
"-",
"value",
"pair",
"is",
"stored",
"in",
"a",
"seperate",
"file",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/util/file_storage.go#L24-L34 |
9,286 | brutella/hc | util/file_storage.go | Set | func (f *fileStorage) Set(key string, value []byte) error {
file, err := f.fileForWrite(key)
if err != nil {
return err
}
defer file.Close()
_, err = file.Write(value)
return err
} | go | func (f *fileStorage) Set(key string, value []byte) error {
file, err := f.fileForWrite(key)
if err != nil {
return err
}
defer file.Close()
_, err = file.Write(value)
return err
} | [
"func",
"(",
"f",
"*",
"fileStorage",
")",
"Set",
"(",
"key",
"string",
",",
"value",
"[",
"]",
"byte",
")",
"error",
"{",
"file",
",",
"err",
":=",
"f",
".",
"fileForWrite",
"(",
"key",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n\n",
"_",
",",
"err",
"=",
"file",
".",
"Write",
"(",
"value",
")",
"\n",
"return",
"err",
"\n",
"}"
]
| // Set sets the value for a specific key. | [
"Set",
"sets",
"the",
"value",
"for",
"a",
"specific",
"key",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/util/file_storage.go#L37-L48 |
9,287 | brutella/hc | util/file_storage.go | Get | func (f *fileStorage) Get(key string) ([]byte, error) {
file, err := f.fileForRead(key)
if err != nil {
return nil, err
}
defer file.Close()
var b bytes.Buffer
var buffer = make([]byte, 32)
for {
n, _ := file.Read(buffer)
if n > 0 {
b.Write(buffer[:n])
} else {
break
}
}
return b.Bytes(), nil
} | go | func (f *fileStorage) Get(key string) ([]byte, error) {
file, err := f.fileForRead(key)
if err != nil {
return nil, err
}
defer file.Close()
var b bytes.Buffer
var buffer = make([]byte, 32)
for {
n, _ := file.Read(buffer)
if n > 0 {
b.Write(buffer[:n])
} else {
break
}
}
return b.Bytes(), nil
} | [
"func",
"(",
"f",
"*",
"fileStorage",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"f",
".",
"fileForRead",
"(",
"key",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n\n",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"var",
"buffer",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"32",
")",
"\n",
"for",
"{",
"n",
",",
"_",
":=",
"file",
".",
"Read",
"(",
"buffer",
")",
"\n",
"if",
"n",
">",
"0",
"{",
"b",
".",
"Write",
"(",
"buffer",
"[",
":",
"n",
"]",
")",
"\n",
"}",
"else",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"b",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
]
| // Get returns the value for a specific key. | [
"Get",
"returns",
"the",
"value",
"for",
"a",
"specific",
"key",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/util/file_storage.go#L51-L72 |
9,288 | brutella/hc | util/file_storage.go | Delete | func (f *fileStorage) Delete(key string) error {
return os.Remove(f.filePathToFile(key))
} | go | func (f *fileStorage) Delete(key string) error {
return os.Remove(f.filePathToFile(key))
} | [
"func",
"(",
"f",
"*",
"fileStorage",
")",
"Delete",
"(",
"key",
"string",
")",
"error",
"{",
"return",
"os",
".",
"Remove",
"(",
"f",
".",
"filePathToFile",
"(",
"key",
")",
")",
"\n",
"}"
]
| // Delete removes the file for the corresponding key. | [
"Delete",
"removes",
"the",
"file",
"for",
"the",
"corresponding",
"key",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/util/file_storage.go#L75-L77 |
9,289 | brutella/hc | hap/pair/setup_server_session.go | NewSetupServerSession | func NewSetupServerSession(username, pin string) (*SetupServerSession, error) {
var err error
pairName := []byte("Pair-Setup")
srp, err := srp.NewSRP(SRPGroup, sha512.New, KeyDerivativeFuncRFC2945(sha512.New, []byte(pairName)))
if err == nil {
srp.SaltLength = 16
salt, v, err := srp.ComputeVerifier([]byte(pin))
if err == nil {
session := srp.NewServerSession([]byte(pairName), salt, v)
pairing := SetupServerSession{
session: session,
Salt: salt,
PublicKey: session.GetB(),
Username: []byte(username),
}
return &pairing, nil
}
}
return nil, err
} | go | func NewSetupServerSession(username, pin string) (*SetupServerSession, error) {
var err error
pairName := []byte("Pair-Setup")
srp, err := srp.NewSRP(SRPGroup, sha512.New, KeyDerivativeFuncRFC2945(sha512.New, []byte(pairName)))
if err == nil {
srp.SaltLength = 16
salt, v, err := srp.ComputeVerifier([]byte(pin))
if err == nil {
session := srp.NewServerSession([]byte(pairName), salt, v)
pairing := SetupServerSession{
session: session,
Salt: salt,
PublicKey: session.GetB(),
Username: []byte(username),
}
return &pairing, nil
}
}
return nil, err
} | [
"func",
"NewSetupServerSession",
"(",
"username",
",",
"pin",
"string",
")",
"(",
"*",
"SetupServerSession",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"pairName",
":=",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
"\n",
"srp",
",",
"err",
":=",
"srp",
".",
"NewSRP",
"(",
"SRPGroup",
",",
"sha512",
".",
"New",
",",
"KeyDerivativeFuncRFC2945",
"(",
"sha512",
".",
"New",
",",
"[",
"]",
"byte",
"(",
"pairName",
")",
")",
")",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"srp",
".",
"SaltLength",
"=",
"16",
"\n",
"salt",
",",
"v",
",",
"err",
":=",
"srp",
".",
"ComputeVerifier",
"(",
"[",
"]",
"byte",
"(",
"pin",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"session",
":=",
"srp",
".",
"NewServerSession",
"(",
"[",
"]",
"byte",
"(",
"pairName",
")",
",",
"salt",
",",
"v",
")",
"\n",
"pairing",
":=",
"SetupServerSession",
"{",
"session",
":",
"session",
",",
"Salt",
":",
"salt",
",",
"PublicKey",
":",
"session",
".",
"GetB",
"(",
")",
",",
"Username",
":",
"[",
"]",
"byte",
"(",
"username",
")",
",",
"}",
"\n",
"return",
"&",
"pairing",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"err",
"\n",
"}"
]
| // NewSetupServerSession return a new setup server session. | [
"NewSetupServerSession",
"return",
"a",
"new",
"setup",
"server",
"session",
"."
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/setup_server_session.go#L23-L44 |
9,290 | brutella/hc | hap/pair/setup_server_session.go | SetupPrivateKeyFromClientPublicKey | func (p *SetupServerSession) SetupPrivateKeyFromClientPublicKey(key []byte) error {
key, err := p.session.ComputeKey(key) // S
if err == nil {
p.PrivateKey = key
}
return err
} | go | func (p *SetupServerSession) SetupPrivateKeyFromClientPublicKey(key []byte) error {
key, err := p.session.ComputeKey(key) // S
if err == nil {
p.PrivateKey = key
}
return err
} | [
"func",
"(",
"p",
"*",
"SetupServerSession",
")",
"SetupPrivateKeyFromClientPublicKey",
"(",
"key",
"[",
"]",
"byte",
")",
"error",
"{",
"key",
",",
"err",
":=",
"p",
".",
"session",
".",
"ComputeKey",
"(",
"key",
")",
"// S",
"\n",
"if",
"err",
"==",
"nil",
"{",
"p",
".",
"PrivateKey",
"=",
"key",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // SetupPrivateKeyFromClientPublicKey calculates and internally sets secret key `S` based on client public key `A` | [
"SetupPrivateKeyFromClientPublicKey",
"calculates",
"and",
"internally",
"sets",
"secret",
"key",
"S",
"based",
"on",
"client",
"public",
"key",
"A"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/setup_server_session.go#L56-L63 |
9,291 | brutella/hc | hap/pair/setup_server_session.go | SetupEncryptionKey | func (p *SetupServerSession) SetupEncryptionKey(salt []byte, info []byte) error {
hash, err := hkdf.Sha512(p.PrivateKey, salt, info)
if err == nil {
p.EncryptionKey = hash
}
return err
} | go | func (p *SetupServerSession) SetupEncryptionKey(salt []byte, info []byte) error {
hash, err := hkdf.Sha512(p.PrivateKey, salt, info)
if err == nil {
p.EncryptionKey = hash
}
return err
} | [
"func",
"(",
"p",
"*",
"SetupServerSession",
")",
"SetupEncryptionKey",
"(",
"salt",
"[",
"]",
"byte",
",",
"info",
"[",
"]",
"byte",
")",
"error",
"{",
"hash",
",",
"err",
":=",
"hkdf",
".",
"Sha512",
"(",
"p",
".",
"PrivateKey",
",",
"salt",
",",
"info",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"p",
".",
"EncryptionKey",
"=",
"hash",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // SetupEncryptionKey calculates and internally sets encryption key `K` based on salt and info
//
// Only 32 bytes are used from HKDF-SHA512 | [
"SetupEncryptionKey",
"calculates",
"and",
"internally",
"sets",
"encryption",
"key",
"K",
"based",
"on",
"salt",
"and",
"info",
"Only",
"32",
"bytes",
"are",
"used",
"from",
"HKDF",
"-",
"SHA512"
]
| e301c8e55cb063ac61007bd632f9bda2d700557e | https://github.com/brutella/hc/blob/e301c8e55cb063ac61007bd632f9bda2d700557e/hap/pair/setup_server_session.go#L68-L75 |
9,292 | leanovate/gopter | commands/command.go | Run | func (p *ProtoCommand) Run(systemUnderTest SystemUnderTest) Result {
if p.RunFunc != nil {
return p.RunFunc(systemUnderTest)
}
return nil
} | go | func (p *ProtoCommand) Run(systemUnderTest SystemUnderTest) Result {
if p.RunFunc != nil {
return p.RunFunc(systemUnderTest)
}
return nil
} | [
"func",
"(",
"p",
"*",
"ProtoCommand",
")",
"Run",
"(",
"systemUnderTest",
"SystemUnderTest",
")",
"Result",
"{",
"if",
"p",
".",
"RunFunc",
"!=",
"nil",
"{",
"return",
"p",
".",
"RunFunc",
"(",
"systemUnderTest",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Run applies the command to the system under test | [
"Run",
"applies",
"the",
"command",
"to",
"the",
"system",
"under",
"test"
]
| 634a59d12406abc51545000deab7cf43ebc32378 | https://github.com/leanovate/gopter/blob/634a59d12406abc51545000deab7cf43ebc32378/commands/command.go#L39-L44 |
9,293 | leanovate/gopter | commands/command.go | NextState | func (p *ProtoCommand) NextState(state State) State {
if p.NextStateFunc != nil {
return p.NextStateFunc(state)
}
return state
} | go | func (p *ProtoCommand) NextState(state State) State {
if p.NextStateFunc != nil {
return p.NextStateFunc(state)
}
return state
} | [
"func",
"(",
"p",
"*",
"ProtoCommand",
")",
"NextState",
"(",
"state",
"State",
")",
"State",
"{",
"if",
"p",
".",
"NextStateFunc",
"!=",
"nil",
"{",
"return",
"p",
".",
"NextStateFunc",
"(",
"state",
")",
"\n",
"}",
"\n",
"return",
"state",
"\n",
"}"
]
| // NextState calculates the next expected state if the command is applied | [
"NextState",
"calculates",
"the",
"next",
"expected",
"state",
"if",
"the",
"command",
"is",
"applied"
]
| 634a59d12406abc51545000deab7cf43ebc32378 | https://github.com/leanovate/gopter/blob/634a59d12406abc51545000deab7cf43ebc32378/commands/command.go#L47-L52 |
9,294 | leanovate/gopter | commands/command.go | PreCondition | func (p *ProtoCommand) PreCondition(state State) bool {
if p.PreConditionFunc != nil {
return p.PreConditionFunc(state)
}
return true
} | go | func (p *ProtoCommand) PreCondition(state State) bool {
if p.PreConditionFunc != nil {
return p.PreConditionFunc(state)
}
return true
} | [
"func",
"(",
"p",
"*",
"ProtoCommand",
")",
"PreCondition",
"(",
"state",
"State",
")",
"bool",
"{",
"if",
"p",
".",
"PreConditionFunc",
"!=",
"nil",
"{",
"return",
"p",
".",
"PreConditionFunc",
"(",
"state",
")",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
]
| // PreCondition checks if the state is valid before the command is applied | [
"PreCondition",
"checks",
"if",
"the",
"state",
"is",
"valid",
"before",
"the",
"command",
"is",
"applied"
]
| 634a59d12406abc51545000deab7cf43ebc32378 | https://github.com/leanovate/gopter/blob/634a59d12406abc51545000deab7cf43ebc32378/commands/command.go#L55-L60 |
9,295 | leanovate/gopter | commands/command.go | PostCondition | func (p *ProtoCommand) PostCondition(state State, result Result) *gopter.PropResult {
if p.PostConditionFunc != nil {
return p.PostConditionFunc(state, result)
}
return &gopter.PropResult{Status: gopter.PropTrue}
} | go | func (p *ProtoCommand) PostCondition(state State, result Result) *gopter.PropResult {
if p.PostConditionFunc != nil {
return p.PostConditionFunc(state, result)
}
return &gopter.PropResult{Status: gopter.PropTrue}
} | [
"func",
"(",
"p",
"*",
"ProtoCommand",
")",
"PostCondition",
"(",
"state",
"State",
",",
"result",
"Result",
")",
"*",
"gopter",
".",
"PropResult",
"{",
"if",
"p",
".",
"PostConditionFunc",
"!=",
"nil",
"{",
"return",
"p",
".",
"PostConditionFunc",
"(",
"state",
",",
"result",
")",
"\n",
"}",
"\n",
"return",
"&",
"gopter",
".",
"PropResult",
"{",
"Status",
":",
"gopter",
".",
"PropTrue",
"}",
"\n",
"}"
]
| // PostCondition checks if the state is valid after the command is applied | [
"PostCondition",
"checks",
"if",
"the",
"state",
"is",
"valid",
"after",
"the",
"command",
"is",
"applied"
]
| 634a59d12406abc51545000deab7cf43ebc32378 | https://github.com/leanovate/gopter/blob/634a59d12406abc51545000deab7cf43ebc32378/commands/command.go#L63-L68 |
9,296 | leanovate/gopter | gen/time.go | TimeRange | func TimeRange(from time.Time, duration time.Duration) gopter.Gen {
return func(genParams *gopter.GenParameters) *gopter.GenResult {
v := from.Add(time.Duration(genParams.Rng.Int63n(int64(duration))))
return gopter.NewGenResult(v, TimeShrinker)
}
} | go | func TimeRange(from time.Time, duration time.Duration) gopter.Gen {
return func(genParams *gopter.GenParameters) *gopter.GenResult {
v := from.Add(time.Duration(genParams.Rng.Int63n(int64(duration))))
return gopter.NewGenResult(v, TimeShrinker)
}
} | [
"func",
"TimeRange",
"(",
"from",
"time",
".",
"Time",
",",
"duration",
"time",
".",
"Duration",
")",
"gopter",
".",
"Gen",
"{",
"return",
"func",
"(",
"genParams",
"*",
"gopter",
".",
"GenParameters",
")",
"*",
"gopter",
".",
"GenResult",
"{",
"v",
":=",
"from",
".",
"Add",
"(",
"time",
".",
"Duration",
"(",
"genParams",
".",
"Rng",
".",
"Int63n",
"(",
"int64",
"(",
"duration",
")",
")",
")",
")",
"\n",
"return",
"gopter",
".",
"NewGenResult",
"(",
"v",
",",
"TimeShrinker",
")",
"\n",
"}",
"\n",
"}"
]
| // TimeRange generates an arbitrary time.Time with a range
// from defines the start of the time range
// duration defines the overall duration of the time range | [
"TimeRange",
"generates",
"an",
"arbitrary",
"time",
".",
"Time",
"with",
"a",
"range",
"from",
"defines",
"the",
"start",
"of",
"the",
"time",
"range",
"duration",
"defines",
"the",
"overall",
"duration",
"of",
"the",
"time",
"range"
]
| 634a59d12406abc51545000deab7cf43ebc32378 | https://github.com/leanovate/gopter/blob/634a59d12406abc51545000deab7cf43ebc32378/gen/time.go#L32-L37 |
9,297 | leanovate/gopter | gen/complex_shrink.go | Complex128Shrinker | func Complex128Shrinker(v interface{}) gopter.Shrink {
c := v.(complex128)
realShrink := Float64Shrinker(real(c)).Map(func(r float64) complex128 {
return complex(r, imag(c))
})
imagShrink := Float64Shrinker(imag(c)).Map(func(i float64) complex128 {
return complex(real(c), i)
})
return realShrink.Interleave(imagShrink)
} | go | func Complex128Shrinker(v interface{}) gopter.Shrink {
c := v.(complex128)
realShrink := Float64Shrinker(real(c)).Map(func(r float64) complex128 {
return complex(r, imag(c))
})
imagShrink := Float64Shrinker(imag(c)).Map(func(i float64) complex128 {
return complex(real(c), i)
})
return realShrink.Interleave(imagShrink)
} | [
"func",
"Complex128Shrinker",
"(",
"v",
"interface",
"{",
"}",
")",
"gopter",
".",
"Shrink",
"{",
"c",
":=",
"v",
".",
"(",
"complex128",
")",
"\n",
"realShrink",
":=",
"Float64Shrinker",
"(",
"real",
"(",
"c",
")",
")",
".",
"Map",
"(",
"func",
"(",
"r",
"float64",
")",
"complex128",
"{",
"return",
"complex",
"(",
"r",
",",
"imag",
"(",
"c",
")",
")",
"\n",
"}",
")",
"\n",
"imagShrink",
":=",
"Float64Shrinker",
"(",
"imag",
"(",
"c",
")",
")",
".",
"Map",
"(",
"func",
"(",
"i",
"float64",
")",
"complex128",
"{",
"return",
"complex",
"(",
"real",
"(",
"c",
")",
",",
"i",
")",
"\n",
"}",
")",
"\n",
"return",
"realShrink",
".",
"Interleave",
"(",
"imagShrink",
")",
"\n",
"}"
]
| // Complex128Shrinker is a shrinker for complex128 numbers | [
"Complex128Shrinker",
"is",
"a",
"shrinker",
"for",
"complex128",
"numbers"
]
| 634a59d12406abc51545000deab7cf43ebc32378 | https://github.com/leanovate/gopter/blob/634a59d12406abc51545000deab7cf43ebc32378/gen/complex_shrink.go#L6-L15 |
9,298 | leanovate/gopter | gen/complex_shrink.go | Complex64Shrinker | func Complex64Shrinker(v interface{}) gopter.Shrink {
c := v.(complex64)
realShrink := Float64Shrinker(float64(real(c))).Map(func(r float64) complex64 {
return complex(float32(r), imag(c))
})
imagShrink := Float64Shrinker(float64(imag(c))).Map(func(i float64) complex64 {
return complex(real(c), float32(i))
})
return realShrink.Interleave(imagShrink)
} | go | func Complex64Shrinker(v interface{}) gopter.Shrink {
c := v.(complex64)
realShrink := Float64Shrinker(float64(real(c))).Map(func(r float64) complex64 {
return complex(float32(r), imag(c))
})
imagShrink := Float64Shrinker(float64(imag(c))).Map(func(i float64) complex64 {
return complex(real(c), float32(i))
})
return realShrink.Interleave(imagShrink)
} | [
"func",
"Complex64Shrinker",
"(",
"v",
"interface",
"{",
"}",
")",
"gopter",
".",
"Shrink",
"{",
"c",
":=",
"v",
".",
"(",
"complex64",
")",
"\n",
"realShrink",
":=",
"Float64Shrinker",
"(",
"float64",
"(",
"real",
"(",
"c",
")",
")",
")",
".",
"Map",
"(",
"func",
"(",
"r",
"float64",
")",
"complex64",
"{",
"return",
"complex",
"(",
"float32",
"(",
"r",
")",
",",
"imag",
"(",
"c",
")",
")",
"\n",
"}",
")",
"\n",
"imagShrink",
":=",
"Float64Shrinker",
"(",
"float64",
"(",
"imag",
"(",
"c",
")",
")",
")",
".",
"Map",
"(",
"func",
"(",
"i",
"float64",
")",
"complex64",
"{",
"return",
"complex",
"(",
"real",
"(",
"c",
")",
",",
"float32",
"(",
"i",
")",
")",
"\n",
"}",
")",
"\n",
"return",
"realShrink",
".",
"Interleave",
"(",
"imagShrink",
")",
"\n",
"}"
]
| // Complex64Shrinker is a shrinker for complex64 numbers | [
"Complex64Shrinker",
"is",
"a",
"shrinker",
"for",
"complex64",
"numbers"
]
| 634a59d12406abc51545000deab7cf43ebc32378 | https://github.com/leanovate/gopter/blob/634a59d12406abc51545000deab7cf43ebc32378/gen/complex_shrink.go#L18-L27 |
9,299 | leanovate/gopter | gen_parameters.go | WithSize | func (p *GenParameters) WithSize(size int) *GenParameters {
newParameters := *p
newParameters.MaxSize = size
return &newParameters
} | go | func (p *GenParameters) WithSize(size int) *GenParameters {
newParameters := *p
newParameters.MaxSize = size
return &newParameters
} | [
"func",
"(",
"p",
"*",
"GenParameters",
")",
"WithSize",
"(",
"size",
"int",
")",
"*",
"GenParameters",
"{",
"newParameters",
":=",
"*",
"p",
"\n",
"newParameters",
".",
"MaxSize",
"=",
"size",
"\n",
"return",
"&",
"newParameters",
"\n",
"}"
]
| // WithSize modifies the size parameter. The size parameter defines an upper bound for the size of
// generated slices or strings. | [
"WithSize",
"modifies",
"the",
"size",
"parameter",
".",
"The",
"size",
"parameter",
"defines",
"an",
"upper",
"bound",
"for",
"the",
"size",
"of",
"generated",
"slices",
"or",
"strings",
"."
]
| 634a59d12406abc51545000deab7cf43ebc32378 | https://github.com/leanovate/gopter/blob/634a59d12406abc51545000deab7cf43ebc32378/gen_parameters.go#L18-L22 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.