Skip to content

Commit

Permalink
Update client.go
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsurfing committed Jun 8, 2021
1 parent 6488a78 commit 830c7dc
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type ResolverInfo struct {
// SetCertInfo and validates DNSCrypt certificate from the given dns message
// Data received during this call is then used for DNS requests encryption/decryption
// stampStr is an sdns:// address which is parsed using go-dnsstamps package
func (c *Client) SetCertInfo(stampStr string,r dns.Msg) (*ResolverInfo, error) {
func (c *Client) SetCertInfo(stampStr string, r dns.Msg) (*ResolverInfo, error) {
stamp, err := dnsstamps.NewServerStampFromString(stampStr)
if err != nil {
// Invalid SDNS stamp
Expand All @@ -45,7 +45,7 @@ func (c *Client) SetCertInfo(stampStr string,r dns.Msg) (*ResolverInfo, error) {
return nil, ErrInvalidDNSStamp
}

return c.SetCertInfoStamp(stamp,r)
return c.SetCertInfoStamp(stamp, r)
}

// Dial fetches and validates DNSCrypt certificate from the given server
Expand All @@ -65,10 +65,9 @@ func (c *Client) Dial(stampStr string) (*ResolverInfo, error) {
return c.DialStamp(stamp)
}


// SetCertInfoStamp set and validates DNSCrypt certificate from the given server
// Data received during this call is then used for DNS requests encryption/decryption
func (c *Client) SetCertInfoStamp(stamp dnsstamps.ServerStamp,r dns.Msg) (*ResolverInfo, error) {
func (c *Client) SetCertInfoStamp(stamp dnsstamps.ServerStamp, r dns.Msg) (*ResolverInfo, error) {
resolverInfo := &ResolverInfo{}

// Generate the secret/public pair
Expand All @@ -79,7 +78,7 @@ func (c *Client) SetCertInfoStamp(stamp dnsstamps.ServerStamp,r dns.Msg) (*Resol
resolverInfo.ServerAddress = stamp.ServerAddrStr
resolverInfo.ProviderName = stamp.ProviderName

cert, err := c.fetchCert(stamp,r)
cert, err := c.setCertInfo(stamp, r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -107,7 +106,7 @@ func (c *Client) DialStamp(stamp dnsstamps.ServerStamp) (*ResolverInfo, error) {
resolverInfo.ServerAddress = stamp.ServerAddrStr
resolverInfo.ProviderName = stamp.ProviderName

cert, err := c.fetchCertPlaintext(stamp)
cert, err := c.fetchCert(stamp)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -248,8 +247,9 @@ func (c *Client) decrypt(b []byte, resolverInfo *ResolverInfo) (*dns.Msg, error)
}
return res, nil
}

//fetchCertPlaintext loads DNSCrypt record from the specified server
func (c *Client) fetchCertPlaintext(stamp dnsstamps.ServerStamp) (*Cert, error){
func (c *Client) fetchCert(stamp dnsstamps.ServerStamp) (*Cert, error) {
providerName := stamp.ProviderName
if !strings.HasSuffix(providerName, ".") {
providerName = providerName + "."
Expand All @@ -265,11 +265,11 @@ func (c *Client) fetchCertPlaintext(stamp dnsstamps.ServerStamp) (*Cert, error){
if r.Rcode != dns.RcodeSuccess {
return nil, ErrFailedToFetchCert
}
return c.fetchCert(stamp,*r)
return c.setCertInfo(stamp, *r)
}

// fetchCert set DNSCrypt cert
func (c *Client) fetchCert(stamp dnsstamps.ServerStamp,r dns.Msg) (*Cert, error) {
func (c *Client) setCertInfo(stamp dnsstamps.ServerStamp, r dns.Msg) (*Cert, error) {
providerName := stamp.ProviderName
if !strings.HasSuffix(providerName, ".") {
providerName = providerName + "."
Expand Down

0 comments on commit 830c7dc

Please sign in to comment.