Class: Sphragis::Providers::HaricaProvider

Inherits:
BaseProvider show all
Defined in:
lib/sphragis/providers/harica_provider.rb

Overview

Harica (Hellenic Academic and Research Institutions CA) Provider Harica provides free digital certificates for academic institutions in Greece and paid certificates for commercial use.

Constant Summary collapse

HARICA_API_BASE =
"https://api.harica.gr/v1"

Instance Attribute Summary

Attributes inherited from BaseProvider

#config

Instance Method Summary collapse

Methods inherited from BaseProvider

#connected?, #provider_name

Constructor Details

#initialize(config = {}) ⇒ HaricaProvider

Initialize Harica provider



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sphragis/providers/harica_provider.rb', line 27

def initialize(config = {})
  super
  @config = {
    api_key: config[:api_key],
    certificate_id: config[:certificate_id],
    username: config[:username],
    password: config[:password],
    environment: config[:environment] || "production"
  }
  @api_base = @config[:environment] == "sandbox" ? "#{HARICA_API_BASE}/sandbox" : HARICA_API_BASE
end

Instance Method Details

#certificateObject

Raises:



81
82
83
84
85
86
# File 'lib/sphragis/providers/harica_provider.rb', line 81

def certificate
  raise ProviderError, "Not connected to Harica" unless connected?

  # In a real implementation, fetch certificate details from Harica API
  simulate_harica_certificate
end

#connectObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sphragis/providers/harica_provider.rb', line 39

def connect
  validate_configuration!

  # Authenticate with Harica API
  # In a real implementation, this would call the Harica authentication endpoint
  response = authenticate_with_harica

  @session = {
    connected: true,
    provider: "harica",
    access_token: response[:access_token],
    token_expires_at: Time.now + 3600,
    certificate_id: @config[:certificate_id]
  }
  true
rescue StandardError => e
  raise ProviderError, "Failed to connect to Harica: #{e.message}"
end

#disconnectObject



58
59
60
61
62
63
# File 'lib/sphragis/providers/harica_provider.rb', line 58

def disconnect
  # Revoke session if needed
  # In a real implementation, call Harica logout endpoint
  @session = nil
  true
end

#service_available?Boolean

Check if Harica service is available



96
97
98
99
# File 'lib/sphragis/providers/harica_provider.rb', line 96

def service_available?
  # In production, this would ping Harica's health endpoint
  true
end

#sign(data) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/sphragis/providers/harica_provider.rb', line 65

def sign(data)
  raise ProviderError, "Not connected to Harica" unless connected?

  # Check if token is still valid
  refresh_token_if_needed

  # In a real implementation, this would:
  # 1. Send data to Harica signing endpoint
  # 2. Use the certificate_id to identify which certificate to use
  # 3. Return the signed data with Harica's signature

  simulate_harica_signing(data)
rescue StandardError => e
  raise ProviderError, "Failed to sign with Harica: #{e.message}"
end

#validate_configuration!Object

Raises:



88
89
90
91
92
# File 'lib/sphragis/providers/harica_provider.rb', line 88

def validate_configuration!
  raise ProviderError, "Harica API key not configured" if @config[:api_key].nil?
  raise ProviderError, "Harica certificate ID not configured" if @config[:certificate_id].nil?
  raise ProviderError, "Harica username not configured" if @config[:username].nil?
end