AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Delphi Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0
Thema durchsuchen
Ansicht
Themen-Optionen

Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0

Ein Thema von haentschman · begonnen am 11. Jan 2024 · letzter Beitrag vom 31. Jan 2024
Antwort Antwort
Kas Ob.

Registriert seit: 3. Sep 2023
435 Beiträge
 
#1

AW: Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0

  Alt 27. Jan 2024, 13:22
I looked at the library,
ValidFormat and ValidHash supposed to be working as factory design, you feed them a class type and will get a class, this implementation to remove the need to hardcode a switch between algorithms.

https://en.wikipedia.org/wiki/Factory_method_pattern
but with simple function instead of a class.
I'm not completely sure yet what you want to tell with this.
Is this something which should be changed in DEC?
Did I mess up something? If so, how should it be changed?
Or was this just some explanation of where the OP's problem comes from?
ValidFormat is used as generic or general use function that can be used to one hit call, But ValidHash it seems was working in DEC v5 but with all the refactoring and separating code in different specialized units with DEC v6 it did lose the functionality code form TDECHashAuthentication.

I think DEC v6 should add/have an interface (IDECHashAuthentication) to TDECHash like this :
Zitat:
{$IFDEF FPC}
TDECHash = class(TDECObject) // does not find methods of the interface as it
// searches for AnsiString instead of RawByteString
// and thus does not find that
private
{$ELSE}
TDECHash = class(TDECObject, IDECHash, IDECHashAuthentication)
strict private
{$ENDIF}
Code:
  {$IFDEF FPC}
  TDECHash = class(TDECObject) // does not find methods of the interface as it
                                // searches for AnsiString instead of RawByteString
                                // and thus does not find that
  private
  {$ELSE}
  TDECHash = class(TDECObject, IDECHash, IDECHashAuthentication)
  strict private
  {$ENDIF}
That is the cause for the failure or the incompatibility in the code in first place with DECv5.

That one way to fix it, or without an interface with different ValidPasswordHash that solve this, yet it will fail or need more and bigger adjustment to the code, the core problem is TDECHashClass doesn't implement/import/offer the publics/interface of TDECHashAuthentication.
Kas
  Mit Zitat antworten Zitat
TurboMagic

Registriert seit: 28. Feb 2016
Ort: Nordost Baden-Württemberg
3.076 Beiträge
 
Delphi 12 Athens
 
#2

AW: Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0

  Alt 27. Jan 2024, 13:43
Thanks for this input!
It should be doable to add this.
Is it possible that you add this to the issue tracker
over here so I won't forget it? (just the text of your post)
I'm currently working else but try to get some time for DEC
in the forseable future.

https://github.com/MHumm/DelphiEncry...pendium/issues
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
435 Beiträge
 
#3

AW: Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0

  Alt 27. Jan 2024, 14:00
I am really sorry, but i don't even have an account on GitHub !
Kas
  Mit Zitat antworten Zitat
TurboMagic

Registriert seit: 28. Feb 2016
Ort: Nordost Baden-Württemberg
3.076 Beiträge
 
Delphi 12 Athens
 
#4

AW: Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0

  Alt 27. Jan 2024, 17:01
Ok, then I'll make a note somewhere to implement this.
  Mit Zitat antworten Zitat
TurboMagic

Registriert seit: 28. Feb 2016
Ort: Nordost Baden-Württemberg
3.076 Beiträge
 
Delphi 12 Athens
 
#5

AW: Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0

  Alt 28. Jan 2024, 10:05
I looked at the library,
ValidFormat and ValidHash supposed to be working as factory design, you feed them a class type and will get a class, this implementation to remove the need to hardcode a switch between algorithms.

https://en.wikipedia.org/wiki/Factory_method_pattern
but with simple function instead of a class.
I'm not completely sure yet what you want to tell with this.
Is this something which should be changed in DEC?
Did I mess up something? If so, how should it be changed?
Or was this just some explanation of where the OP's problem comes from?
ValidFormat is used as generic or general use function that can be used to one hit call, But ValidHash it seems was working in DEC v5 but with all the refactoring and separating code in different specialized units with DEC v6 it did lose the functionality code form TDECHashAuthentication.

I think DEC v6 should add/have an interface (IDECHashAuthentication) to TDECHash like this :
Zitat:
{$IFDEF FPC}
TDECHash = class(TDECObject) // does not find methods of the interface as it
// searches for AnsiString instead of RawByteString
// and thus does not find that
private
{$ELSE}
TDECHash = class(TDECObject, IDECHash, IDECHashAuthentication)
strict private
{$ENDIF}
Code:
  {$IFDEF FPC}
  TDECHash = class(TDECObject) // does not find methods of the interface as it
                                // searches for AnsiString instead of RawByteString
                                // and thus does not find that
  private
  {$ELSE}
  TDECHash = class(TDECObject, IDECHash, IDECHashAuthentication)
  strict private
  {$ENDIF}
That is the cause for the failure or the incompatibility in the code in first place with DECv5.

That one way to fix it, or without an interface with different ValidPasswordHash that solve this, yet it will fail or need more and bigger adjustment to the code, the core problem is TDECHashClass doesn't implement/import/offer the publics/interface of TDECHashAuthentication.
I try to understand what you propose to implement, but I'm not completely sure yet this fits the architecture.

1. You want to have an IDECHashAUthentication interface, containing all the public class methods of that one.
That's doable and I'll do that in a minute.

2. You want TDECHashClass to declare it implements this interface. In order to do this TDECHash would need to
implement this interface, as TDECHashClass is a meta class. But even then this would be against the current
architecture, as this would mean that the base class already implements all these Authentication related methods.
They have been moved to an own using in order to not let DECHashBase grow unwidely. There might be further
authentication methods added in the future and thus the whole thing might grow.

Cheers
TurboMagic
  Mit Zitat antworten Zitat
TurboMagic

Registriert seit: 28. Feb 2016
Ort: Nordost Baden-Württemberg
3.076 Beiträge
 
Delphi 12 Athens
 
#6

AW: Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0

  Alt 28. Jan 2024, 10:09
Ok, the attempt to create an IDECHashAUthentication interface and just add all public class methods
of TDECHashAUthentication to it failed, as the compiler doesn't like class methods in an interface.

How to proceed here?

Cheers
TurboMagic
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
435 Beiträge
 
#7

AW: Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0

  Alt 28. Jan 2024, 11:47
Yes, it is tricky to add IDECHashAuthentication because the class methods, and to solve this either add the same naming methods in TDECHash, so you can redirect all these methods to the class ones in TDECHashAuthentication, or introduce new global function ValidPasswordHash just like ValidHash that return TDECHashAuthentication.

Both approaches are not ideals, the best or the better is MAY BE dropping the class methods and making them simple local methods, but i have no idea what this might break in current build, as these class methods popular or even needed as class methods ?
I can't tell, and believe you have better inside knowledge in DEC design.
Kas
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
435 Beiträge
 
#8

AW: Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0

  Alt 28. Jan 2024, 13:17
I see this discrepancy in the implementation
Code:
// in DECHash.pas
  THashBaseMD4 = class(TDECHashAuthentication)
  THash_SHA0 = class(THashBaseMD4)
  THash_SHA256 = class(THash_SHA0)

// while in DECHashAuthentication.pas
  TDECHashAuthentication = class(TDECHash)

// but in DECHashBase.pas
  TDECHash = class(TDECObject, IDECHash)
Now we left with TDECHash without visibility to TDECHashAuthentication and its class methods, while all the derived class has full functionality of HashAuthentication,

What is misleading is the naming in TDECHashAuthentication, as the main class (core type) to be used is TDECHashAuthenticationClass from DECHashAuthentication.pas, not TDECHashClass from DECHashBase.

With current implementation, de facto the base class is TDECHashAuthentication !

and that why i suggest to not change anything for now, just add documented global function (like ValidPasswordHash) to serve this functionality where the result is TDECHashAuthenticationClass , but the input is TDECHashClass !!
Kas
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
435 Beiträge
 
#9

AW: Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0

  Alt 28. Jan 2024, 13:43
Here this is the smallest workaround the problem for this case like what OP presented.

the modification are only in DECHashAuthentication.pas
Code:
function ValidAuthHash(HashClass: TDECHashClass): TDECHashAuthenticationClass;
procedure SetDefaultAuthHashClass(HashClass: TDECHashClass);

implementation

uses
  DECUtil;

resourcestring
  sAuthHashNoDefault         = 'No default hash has been registered';

var

  FDefaultAutheticationHashClass: TDECHashAuthenticationClass = nil;

function ValidAuthHash(HashClass: TDECHashClass): TDECHashAuthenticationClass;
begin
  if Assigned(HashClass) then
    Result := TDECHashAuthenticationClass(HashClass)
  else
    Result := FDefaultAutheticationHashClass;

  if not Assigned(Result) then
    raise EDECHashException.CreateRes(@sAuthHashNoDefault);
end;

procedure SetDefaultAuthHashClass(HashClass: TDECHashClass);
begin
  Assert(Assigned(HashClass), 'Do not set a nil default hash class!');

  FDefaultAutheticationHashClass := TDECHashAuthenticationClass(HashClass);
end;
For (legacy) code like haentschman the need is to add DECHashAuthentication in uses clause and use ValidAuthHash instead ValidHash.

BUT, they are named/called AuthHash while in fact they are just key deriving methods/algorithms, so.... (i am lousy at naming) ... find a better naming as i took the class name only while the functionality has nothing to do with authentication though.
Kas
  Mit Zitat antworten Zitat
TurboMagic

Registriert seit: 28. Feb 2016
Ort: Nordost Baden-Württemberg
3.076 Beiträge
 
Delphi 12 Athens
 
#10

AW: Hilfe bei Umstellung Unit DEC5.1 zu DEC6.0

  Alt 28. Jan 2024, 17:43
Hello,

I copied your implementation now and renamed it.
We now have

function ValidAuthenticationHash(HashClass: TDECHashClass): TDECHashAuthenticationClass;
procedure SetDefaultAuthenticationHashClass

Best regards

TurboMagic
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:55 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz